Stack Overflow Asked by Python learner 93 on November 12, 2021
I have a function that returns a one item list, like so:
list = [('array_1','array_2')]
I want to change this so that the list is instead a two item one, without the parentheses or single quotes:
list = [array_1,array_2]
What would be the best way to go about doing this?
You could just typecast like this.
list = list([('array_1','array_2')][0])
Answered by marvincyk on November 12, 2021
You can try this:
lst_tuple = [('array_1', 'array_2')]
lst = []
for i in lst_tuple[0]:
lst.append(i)
By iteratating over the list that contains the tuple and appending each item to a new list, you can get this result:
['array_1', 'array_2']
Answered by LoneLegend on November 12, 2021
from itertools import chain
list(chain.from_iterable([('array_1','array_2')]))
['array_1', 'array_2']
Answered by sushanth on November 12, 2021
Try this
lists = [('array_1','array_2')]
print([y for x in lists for y in x])
output
['array_1', 'array_2']
Answered by Umutambyi Gad on November 12, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP