[Tutor] still confused about for loops
Mitya Sirenef
msirenef at lightbird.net
Wed Dec 19 07:30:37 CET 2012
On 12/19/2012 01:19 AM, Brandon Merritt wrote:
> Sorry, I am just so confused and aggravated as to why this won't work
> - why doesn't it print out the whole list? :
>
> number = raw_input('Enter a 7-unit number: ')
>
> for i in number:
> count = []
> count.append(i)
>
> print count
>
> >>> Enter a 7-unit number: 78953298
> ['8']
>
>
Same exact problem as in your first question:
you are resetting the list inside the loop. You
want to move it outside the loop. You could
also do:
count = [i for i in number]
-m
--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
More information about the Tutor
mailing list