Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python merge multiple list inside one variable into one list [duplicate]

I am having a hard time putting multiple list into one because they are all inside one variable.

here is an exemple:

What I have

a = ['1'], ['3'], ['3']

What I want

a = ['1', '3', '3']

How can I resolve that using Python 3.x


EDIT

here is the code I'm working on.

from itertools import chain

def compteur_voyelle(str):
    list_string = "aeoui"
    oldstr = str.lower()
    text = oldstr.replace(" ", "")
    print(text)

    for l in list_string:
        total = text.count(l).__str__()
        answer = list(chain(*total))
        print(answer)

compteur_voyelle("Saitama is the One Punch Man.")

Console Result :

saitamaistheonepunchman.
['4']
['2']
['1']
['1']
['2']
like image 867
Hiroyuki Nuri Avatar asked Dec 25 '22 11:12

Hiroyuki Nuri


1 Answers

You can use itertools.chain.

In [35]: from itertools import chain

In [36]: a = ['1'], ['3'], ['3']

In [37]: list(chain(*a))
Out[37]: ['1', '3', '3']

Or

In [39]: list(chain.from_iterable(a))
Out[39]: ['1', '3', '3']
like image 196
Akavall Avatar answered May 19 '23 01:05

Akavall