I have this list
["[email protected] : martin00", ""],
How do i split so it only be left
[email protected]:martin00
I have this list
["[email protected] : martin00", ""],
How do i split so it only be left
[email protected]:martin00
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.
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 >>>
Abgan, is probably correct, although if you still want a list, ie.,
["[email protected] : martin00"]
you'd want:
the_list[:1]
lists can be accessed by index or sliced into smaller lists.
http://diveintopython.org/native_data_types/lists.html#d0e5623
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(' '))
al = ["[email protected] : martin00", ""],
print al[0][0].replace(" : ", ":")