Prepending string "@" to usernames

Tim Chase python.list at tim.thechases.com
Fri May 24 19:19:40 EDT 2013


On 2013-05-24 19:04, Thomas Murphy wrote:
>> raw_address = "cookielover93 TheGermanHatesSaurkraut
>> WhatsThatBoy932834" address_library = raw_address.split()
>> print address_library
>>
>> final_address = []
>> for address in address_library:
>>     final_address.append("@" + str(address))
>> print final_address
>>
> Exactly it. Thank you so much Dan. Perfect!

Which can be tidily written as a list comprehension:

  final_address = ['@' + address for address in raw_address.split()]

-tkc





More information about the Python-list mailing list