Pythonic way to unpack an iterator inside of a list

后端 未结 5 897
醉酒成梦
醉酒成梦 2020-12-30 16:24

I\'m trying to figure out what is the pythonic way to unpack an iterator inside of a list.

For example:

my_iterator = zip([1, 2, 3, 4], [1, 2, 3, 4]         


        
5条回答
  •  囚心锁ツ
    2020-12-30 16:38

    I tend to use zip if I need to convert a list to a dictionary or use it as a key-value pair in a loop or list comprehension.

    However, if this is only for illustration to create an iterator. I will definitely vote for #3 for clarity.

提交回复
热议问题