I have a small problem with list. So i have a list called l
:
l = ['Facebook;Google+;MySpace', 'Apple;Android']
And as you can see I have only 2 strings in my list. I want to separate my list l
by ';' and put my new 5 strings into a new list called l1
.
How can I do that?
And also I have tried to do this like this:
l1 = l.strip().split(';')
But Python give me an error:
AttributeError: 'list' object has no attribute 'strip'
So if 'list' object has no attribute 'strip' or 'split', how can I split a list?
Thanks
strip()
is a method for strings, you are calling it on alist
, hence the error.To do what you want, just do
Since, you want the elements to be in a single list (and not a list of lists), you have two options.
To do the first, follow the code:
To do the second, use
itertools.chain
You split the string entry of the list. l[0].strip()