8

I have a list of tuples as follows:

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

However, the first element of each tuple is not needed. The desired output is:

[('hi', 'you'), (' bye', 'bye')]

I've done enough research to know I can't manipulate tuples but I can't seem to find an answer on how to successfully remove the first element of each tuple in the list.

Georgy
  • 12,464
  • 7
  • 65
  • 73
user47467
  • 1,045
  • 2
  • 17
  • 34

2 Answers2

14

Firstly tuple is immutable.

Secondly try this approach using a list comprehension:

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

Check slice notation.

Georgy
  • 12,464
  • 7
  • 65
  • 73
xiº
  • 4,605
  • 3
  • 28
  • 39
0

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')]
Georgy
  • 12,464
  • 7
  • 65
  • 73
Martin Evans
  • 45,791
  • 17
  • 81
  • 97