I have a list of tuples:
mylist = [('Bill', 1), ('John', 1), ('Tony', 2), ('Phill', 2)]
I want to remove the quotation marks and the numbers so only names would remain.
I want something like this:
[Bill, John, Tony, Phill]
I have a list of tuples:
mylist = [('Bill', 1), ('John', 1), ('Tony', 2), ('Phill', 2)]
I want to remove the quotation marks and the numbers so only names would remain.
I want something like this:
[Bill, John, Tony, Phill]
Try a list comprehension:
mylist = [('Bill', 1), ('John', 1), ('Tony', 2), ('Phill', 2)]
print([x for x, y in mylist])
Output:
['Bill', 'John', 'Tony', 'Phill']
Or if you also want without quotes, try:
print('[' + ', '.join([x for x, y in mylist]) + ']')
Or zip(*...)
:
print('[' + ', '.join(list(zip(*mylist))[0]) + ']')
Both output:
[Bill, John, Tony, Phill]