0

I have a list as below

list = [(1, 'a'),
 (2, 'b'),
 (3, 'c'),
 (4, 'd'),
 (5, 'e')]

I want to get a list

['a', 'b', 'c', 'd', 'e']

I do like this

newlist = []
for i in range(5):
    newlist.append(list [i][1])

It's a correct way but I guess there is simpler way, isn't it?

Edward
  • 4,443
  • 16
  • 46
  • 81
  • 3
    use a list comprehension: `newlist = [i[1] for i in mylist]`. Also, you should avoid using `list` as a variable name to not override the builtin type `list` – sacuL Jun 08 '18 at 18:15
  • @sacul I've already understood this) – Edward Jun 08 '18 at 18:36

1 Answers1

1

You can use list compression:

new_list = [element[1] for element in list]