-3

I have a list:

List = [('4022-a751',), ('0bfc-4d53',)]

And want to resolve it into the output below:

Output = ['4022-a751','0bfc-4d53']
baduker
  • 15,071
  • 9
  • 26
  • 44
  • 1
    Does this answer your question? [How to make a flat list out of list of lists?](https://stackoverflow.com/questions/952914/how-to-make-a-flat-list-out-of-list-of-lists) – Tomerikoo Sep 16 '20 at 08:02

3 Answers3

2

You should read about List Comprehensions in Python

list_ = [('4022-a751',), ('0bfc-4d53',)]
res = [x for item in list_ for x in item]

Output

['4022-a751', '0bfc-4d53']
AlexisG
  • 2,337
  • 3
  • 8
  • 24
0

A tuple can be manipulated like an array with index.

input_arr = [('4022-a751',), ('0bfc-4d53',)]
output_arr = [a[0] for a in input_arr]

print(output_arr)
yimingStar
  • 43
  • 5
0

You can use this.

old_list= [('4022-a751',), ('0bfc-4d53',)]
new_list = [''.join(i) for i in old_list]
print(new_list)
ron_olo
  • 136
  • 6