Newbie Question: Giving names to Elements of List/Tuple/Dict
Pittaya
a_human_work at hotmail.com
Fri Nov 29 12:08:30 EST 2002
"Alfredo P. Ricafort" <alpot at mylinuxsite.com> wrote in message news:<mailman.1038570941.14619.python-list at python.org>...
> Hi,
>
> I'm quite new to Python. So far I find it to be easy to learn and
> simple to program. However, one thing that I missed, especially someone
> coming from C language, is 'struct'. It seems that when you define a
> data structure in the form of a List, Tuple, or Dict., there is no way
> to give names to each element.
>
> For example:
>
> In C:
> struct Customer {
> char * Name;
> char * Address;
> char * TelNo;
> } Customer[];
>
> printf("Customer Name is %s\n",Customer[i].Name);
>
>
> In Python:
> Customer=[ [Name,Addres,TelNo], [Name,Address,TelNo],.....]
>
> print "Customer Name is %" Customer[i][0]
>
here's one way to do it.
customer1 = { "Name" : None,
"Address" : None,
"TelNo" : None }
Customer = [customer1, customer2, ...]
print "Customer name is %s" % Customer[i]["Name"]
More information about the Python-list
mailing list