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, {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 know that I do Can I output the touple and the level of the code (+ i, -i) , but I was wondering if there was any way to solve the problem completely to use a single understanding .

At present, I is creating two lists and by adding them (which works, unless the order is not necessary):

  & 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

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -