On 05/24/2013 03:53 PM, Thomas Murphy wrote:

<snip>

Here's where I got to:


raw_address = "cookielover93 TheGermanHatesSaurkraut WhatsThatBoy932834"
address_library = [raw_address.split()]
print address_library

for address in address_library:
     final_address = "@" + str(address)
print final_address


However my output is:

[['cookielover93', 'TheGermanHatesSaurkraut', 'WhatsThatBoy932834']]
@['cookielover93', 'TheGermanHatesSaurkraut', 'WhatsThatBoy932834']


I know I'm iterating wrong. May I ask how?

--
Sincerely,
Thomas Murphy
Code Ninja
646.957.6115


No, you're not iterating wrong, but you do have two errors:

1: split() returns a list. You are putting this list (as a single element) inside a list. Drop the square brackets. Make it: address_library = raw_address.split()

2: In your for loop, you want the print _inside_ the loop not outside. IOW, indent the print line. The way you have it written it will only print the _last_ string.

     -=- Larry -=-

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to