tags:

views:

856

answers:

6
+1  Q: 

Python Split?

I have this list

["[email protected] : martin00", ""],

How do i split so it only be left

[email protected]:martin00
+3  A: 

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.

Abgan
+1  A: 

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
    >>> 
Charlie Martin
A: 

Abgan, is probably correct, although if you still want a list, ie.,

["[email protected] : martin00"]

you'd want:

the_list[:1]
Dana
The question suprised me so much, that I posted only the most obvious answer. I'm beginning to doubt if there is really no too newbie questions ;-)
Abgan
I was not correct. He was creating a tuple with a list inside, so he needed to do al[0][0] to retrieve the actual string. See the comma ending the first line of his code?
Abgan
I see it now. It didn't click that it was indicated a tuple, I just figured it was part of his sentence structure :P
Dana
A: 

lists can be accessed by index or sliced into smaller lists.
http://diveintopython.org/native_data_types/lists.html#d0e5623

Yoni Samlan
+2  A: 

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(' '))
SilentGhost
+3  A: 
al = ["[email protected] : martin00", ""],
print al[0][0].replace(" : ", ":")
Ionuț G. Stan