2

I have the following stored in the variable resultset:
(['James Taylor'], ['Sarah Jarosz'], ['Crooked Still'])

I would like to rewrite this as a list, i.e. ['James Taylor', 'Sarah Jarosz', 'Crooked Still' ].

How would I go about this? Thanks in advance

Wallace Mogerty
  • 335
  • 1
  • 5
  • 16
  • 4
    Possible duplicate of [Making a flat list out of list of lists in Python](http://stackoverflow.com/questions/952914/making-a-flat-list-out-of-list-of-lists-in-python). I know your case has a tuple instead of a list, but the solutions listed there apply. There are plenty of other similar questions too like this one: http://stackoverflow.com/questions/18500541/how-to-flatten-a-tuple-in-python – Bahrom Apr 14 '17 at 03:30

2 Answers2

1

In case this is not in fact a duplicate:

resultset = (['James Taylor'], ['Sarah Jarosz'], ['Crooked Still'])
new_list = [i[0] for i in resultset]
print new_list

['James Taylor', 'Sarah Jarosz', 'Crooked Still']

JacobIRR
  • 8,545
  • 8
  • 39
  • 68
1

You can also use:

l = (['James Taylor'], ['Sarah Jarosz'], ['Crooked Still']) 
new_l = [item for sublist in l for item in sublist]
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268