Reputation:
I have this list
["[email protected] : martin00", ""],
How do I split so it only be left with:
[email protected]:martin00
Upvotes: 1
Views: 1992
Reputation: 38075
lists can be accessed by index or sliced into smaller lists.
http://diveintopython3.ep.io/native-datatypes.html
Upvotes: 0
Reputation: 3716
Do you want to have: aList[0]
?
EDIT::
Oh, you have a tuple with the list in it!
Now I see:
al = ["[email protected] : martin00", ""],
#type(al) == tuple
#len(al) == 1
aList = al[0]
#type(aList) == list
#len(aList) == 2
#Now you can type:
aList[0]
#and you get:
"[email protected] : martin00"
You can use aList[0].replace(' : ', ':')
if you wish to remove spaces before and after colon, suit your needs.
I think that the most confusing thing here is the coma ending the first line. It creates a new tuple, that contains your list.
Upvotes: 3
Reputation: 179199
al = ["[email protected] : martin00", ""],
print al[0][0].replace(" : ", ":")
Upvotes: 3
Reputation: 319949
comma at the end means that list is first member of a tuple, but to your question:
in_list = ["[email protected] : martin00", ""]
result = ''.join(in_list[0].split(' '))
Upvotes: 2
Reputation: 32997
Abgan, is probably correct, although if you still want a list, ie.,
["[email protected] : martin00"]
you'd want:
the_list[:1]
Upvotes: 0
Reputation: 112414
Exactly.
$ python Python 2.6 (r26:66714, Dec 4 2008, 11:34:15) [GCC 4.0.1 (Apple Inc. build 5488)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> al = ["[email protected] : martin00", ""] >>> print al[0] [email protected] : martin00 >>>
Upvotes: 1