4

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']
Horai Nuri
  • 5,358
  • 16
  • 75
  • 127

3 Answers3

9

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']
Akavall
  • 82,592
  • 51
  • 207
  • 251
2
a = ['1'], ['3'], ['3']

>>> type(a)
<class 'tuple'> 

a is tuple here. we can covert tuple into list.

>>> a = ['1'], ['3'], ['3']
>>> [value[0] for value in list(a)]
['1', '3', '3']
0

Following the same example as in other answers, i guess this can also be done using the sum built-in :

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

In [2]: sum(a, [])
Out[2]: [1, 3, 3]
mgc
  • 5,223
  • 1
  • 24
  • 37