On 2013-08-06 22:31, Saad Javed wrote: > Thank you for your response. This code has a bug. > > If there is one user left in the user list, it doesn't print a tweet with > just that one user added. For example use this string: "These are my > friends living in the same city as i am. I have known them for years. They > are good people in general. They are:"...you will see that "owais" is still > in the list and is not added to a new tweet and printed.
Good catch, that's my bad, sorry. Because pop() is called on the last element just before the next iteration, when `users' is coerced to a bool, it becomes False in the outer while loop. This affects only 50% of cases because it's possible we will be in the inner loop when we hit the last element in `users', which is why I didn't see it. All that needs to happen is to move the pop to the top of the MAX_LENGTH check: while len(new_message) + len(add) <= MAX_LENGTH: add = " @" + users.pop(0) new_message += add if not users: break
pgpJ22_EEMAoB.pgp
Description: PGP signature
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor