[Tutor] What's the invalid syntax? Code supplied

Alan G alan.gauld at freenet.co.uk
Sun Aug 7 19:23:45 CEST 2005


> What's the invalid syntax? Here is the code:
> import random
> hand = {
>    '0' : ["Ace"]
>    '1' : ["Two"]

Nathan,

You really need to take some time out to read about data structures in 
Python.
You are trying to use a dictionary, with a string as a key and a list 
as a value.
The list has a single string as its content.

As Kent has pointed out you almost certainly can use a number as the 
key and
I'm pretty sure you can get away with the string as the value. Why do 
you
think you need a list as the value? Have you read any tutorial pages 
on
dictionaries? Do you understand the concept of key/value pairs?

You are making life difficult for yourself by picking inappropriate
data structures. You are then posting broken code to the tutor list
with no description of the error, or the error message text, which
makes everyone on the list work much harder to figuure out what might
be wrong! Ultimately it all slows down your work and everyone else
who is contributing to the mailing list.

Sorry if this sounds harsh but I've just come off 3 days of 14 hour
shifts and am probably a bit less patient than normal. But this 
approach
is slowing you down too. You will progress much faster if you take the
time to *understand* what you are doing before doing it!

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list