Removing first elements of tuples in a list

后端 未结 2 1032
萌比男神i
萌比男神i 2021-01-06 02:49

I have a list of tuples as follows:

values = [(\'1\', \'hi\', \'you\'), (\'2\',\' bye\', \'bye\')]

However, the first element of each tuple i

相关标签:
2条回答
  • 2021-01-06 03:27

    You could use the following list comprehension if tuples are not required:

    a_list = [a_tuple[1:] for a_tuple in values]
    print(a_list)
    

    This would print the following:

    [('hi', 'you'), (' bye', 'bye')]
    
    0 讨论(0)
  • 2021-01-06 03:30

    Firstly tuple is immutable.

    Secondly try this approach using a list comprehension:

    a_list = [el[1:] for el in values]
    

    Check slice notation.

    0 讨论(0)
提交回复
热议问题