Advertisement
silver2row

Itertools, Chain, Multiple Ranges, and Lists in Sequence

Feb 3rd, 2020
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # if you want to iterate over multiple ranges/lists in sequence:
  2.  
  3. for i in range(0, 180, 45):
  4.     print(i)
  5. for i in range(180, 0, -45):
  6.     print(i)
  7. for i in [0]:
  8.     print(i)
  9.  
  10.  
  11. # use the "chain" function from itertools to combine the ranges/lists:
  12.  
  13. from itertools import chain
  14.  
  15. for i in chain( range(0, 180, 45), range(180, 0, -45), [0] ):
  16.     print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement