python - Comprehensions: multiple values per iteration -
Is there a way to output two (or more) items of repetition in a list / dictionary / set sense? As a simple example, to output all positive and negative doubles from 1 to 3 (that is, I know that I do Can I output the touple and the level of the code At present, I is creating two lists and by adding them (which works, unless the order is not necessary): {x | x = ± 2n, n รข ???? {1 ... 3} } ), is there a syntax similar to the following?
& gt; & Gt; & Gt; [2 * i, -2 * i Category (1, 4)] [2, -2, 4, -4, 6, -6]
(+ i, -i) , but I was wondering if there was any way to solve the problem completely to use a single understanding .
& gt; & Gt; & Gt; Range (2, 4, 6, -2, -4, -6) Nested for range (1, 4)] for +2 [i (i, 4)] in category i Another form of understanding:
& gt; & Gt; & Gt; ; (2 * i, -2 * i)] [2, -2, 4, -4, 6, -6] / div>
Comments
Post a Comment