-1

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]
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
  • Are you trying to output the array as a string? Please specify what you mean by 'removing' the quotation marks 'from the array'. – Geza Kerecsenyi Jan 11 '21 at 10:27

1 Answers1

2

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]
U13-Forward
  • 69,221
  • 14
  • 89
  • 114