Unpacking tuples in a python list comprehension (cannot use the *-operator)

前端 未结 1 1676
有刺的猬
有刺的猬 2020-12-31 00:31

I am trying to create a list based on another list, with the same values repeated 3 times consecutively.

At the moment, I am using:

>>> my_l         


        
相关标签:
1条回答
  • 2020-12-31 01:02

    You can't use * iterable unpacking in a list comprehension, that syntax is only available in calls, and in Python 3, when using assignments.

    If you want to use a list comprehension, just put your for loops in series; you do want to access the values from my_list directly rather than generate indices though:

    [v for v in my_list for _ in range(3)]
    
    0 讨论(0)
提交回复
热议问题