Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45928

Re: Prepending string "@" to usernames

Date 2013-05-24 18:19 -0500
From Tim Chase <python.list@tim.thechases.com>
Subject Re: Prepending string "@" to usernames
References <CAEcwjcx6WtUMTg=QpqjEZ3fyfUhOLWQ2v-pF4qQ9ypFd3DtByA@mail.gmail.com> <CAGGBd_okY709NyG0BBZSHzv709oTAUNbicMgfOMjo3LjFDipwQ@mail.gmail.com> <CAEcwjcyFYMg6sxND7XE6cKOkab3HB2nA89CBJLp2Cq9g5F3h-A@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2087.1369437469.3114.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Prepending string "@" to usernames Tim Chase <python.list@tim.thechases.com> - 2013-05-24 18:19 -0500

csiph-web