Concatenate list and number in a sublist in Python -
this question has answer here:
- flatten (an irregular) list of lists 35 answers
how concatenate list such this:
buttons = [[['a','b','c'], '2'], [['d','e','f'], '3']] into
buttons = [[['a','b','c','2'], ['d','e','f','3']]] i tried accessing 3 indexes , concatenating didn't work:
buttons[0][1]
>>> import itertools >>> l = [[['a','b','c'], '2'], [['d','e','f'], '3']] >>> [list(itertools.chain.from_iterable(i)) in l] [['a', 'b', 'c', '2'], ['d', 'e', 'f', '3']]
Comments
Post a Comment