Problem with a dictionary program....
danperl at rogers.com
Tue Sep 28 18:21:44 CEST 2004
"Alex Martelli" <aleaxit at yahoo.com> wrote in message
news:1gku3wn.1o7mvyb1gtif84N%aleaxit at yahoo.com...
> Ling Lee <janimal at mail.trillegaarden.dk> wrote:
>> List =
> You're missing 0, so an input such as 103 would give an error even if
> all the rest of your code was correct.
Here's another idea: use a (real) list instead of a dictionary:
Then you have to convert the 'character' variable with int(character) before
indexing in List. Now, this would not help you in learning dictionaries,
but it must be a good lesson for something. ;-)
>> output = 
>> for character in indput:
>> print ', '.join(output)
> This will print N times when you have N digits... outdent the print
> statement so it's executed after the 'for' and not inside it.
That print statement is actually wrong in many ways. It was probably meant
to be something like
print ','.join(List[int(character)]) # List[int(character)], not
but even that would start with ',' and it would be on multiple lines
(probably not your intention). Alex is right. You're better off with an
although that would have square brackets around the output list. Or try an
which would just not have the commas between the numbers
More information about the Python-list