[python] manipulating items in a list

Questions about programming languages and debugging
Post Reply
User avatar
moudy
Technology Enthusiast
Technology Enthusiast
Posts: 688
Joined: 10 Feb 2009, 17:00
15
Location: Beirut, Lebanon

[python] manipulating items in a list

Post by moudy »

hello every one
I'm sort of stuck in this, and I'm not sure how to proceed, although it seems easy,

This is a sample list of emails in python:

Code: Select all

['alain_9999@hotmail.com;', '(a.a_v@hotmail.com);', 'arabesk100@hotmail.com', '(arabesk100@hotmail.com);', 'asfoora-al_hazeena@hotmail.com;', 'atter797@hotmail.com;', 'banooota_shj@hotmail.com;', 'bant2011@hotmail.com;', 'basbosa88@hotmail.com;', 'black_girl_911@hotmail.com;', 'bn_shames_1000@hotmail.com;', 'gardenia_low@hotmail.com;', '(king_almanaseer@hotmail.com);', 'nelldonnie7817@hotmail.com;']
I'm not finding a convenient way to remove the punctuation from the items in the list. I want to remove the semicolons and brackets form the items.
i had in mid to this method:

Code: Select all

for i in list:
         if i.find(';') > -1:
                  i.replace(';'.'')
any ideas ?
I hope I made my self clear enough.
mahmoud_shihab@hotmail.com

User avatar
moudy
Technology Enthusiast
Technology Enthusiast
Posts: 688
Joined: 10 Feb 2009, 17:00
15
Location: Beirut, Lebanon

Re: [python] manipulating items in a list

Post by moudy »

ok solved,
i used this:

Code: Select all

for item in list:
            item.strip(';()')
and it worked just fine
mahmoud_shihab@hotmail.com

Surely
Newbie
Newbie
Posts: 3
Joined: 30 Nov 2010, 08:17
13

Re: [python] manipulating items in a list

Post by Surely »

More functionally you can also do:

Code: Select all

map(lambda email: email.strip('();'), emails)
Where emails is the list of e-mails and the first argument to map() is an anonymous function.

User avatar
moudy
Technology Enthusiast
Technology Enthusiast
Posts: 688
Joined: 10 Feb 2009, 17:00
15
Location: Beirut, Lebanon

Re: [python] manipulating items in a list

Post by moudy »

Thanks a lot for the reply Surely.
mahmoud_shihab@hotmail.com

Post Reply