The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Y.G. Bae (36) [Avatar] Offline
#1
I am just wondering whether it would be more efficient just to call the "name" variable again in the last line because the existing for loop already catches the last name in the iteration after the last space:

names = input("Tell me some names, separated by spaces: ")
name = ""
for ch in names:
    if ch == " ":
        print("Hi", name)
        name = ""
    else:
        name += ch
# deal with the last name given (does not have a space after it)
print("Hi", name)
Ana Bell (33) [Avatar] Offline
#2
You're right, that would be simpler and more "pythonic"!