Re: accessing dictionary keys

2009-10-01 Thread Jerry Hill
On Thu, Oct 1, 2009 at 4:19 PM, Andreas Balogh wrote: > Is there any shortcut which allows to use point.x with a dictionary, or > defining keys with tuples and lists? A namedtuple (introduced in python 2.6), acts like a tuple with named fields. Here's an example: >>> from collections import nam

Re: accessing dictionary keys

2009-10-01 Thread Rami Chowdhury
On Thu, 01 Oct 2009 13:19:18 -0700, Andreas Balogh wrote: Is there any shortcut which allows to use point.x with a dictionary, or defining keys with tuples and lists? Regards, Andreas It sounds like you want collections.namedtuple (Python 2.6 and up; recipe for Python 2.4 or 2.5 at

Re: accessing dictionary keys

2009-10-01 Thread Carsten Haese
Andreas Balogh wrote: > Hello, > > when building a list of points like > > points = [ ] > points.append((1, 2)) > points.append((2, 3)) > > point = points[0] > > eventually I'd like to access the tuple contents in a more descriptive > way, for example: > > print point.x, point.y I'm not sure

accessing dictionary keys

2009-10-01 Thread Andreas Balogh
Hello, when building a list of points like points = [ ] points.append((1, 2)) points.append((2, 3)) point = points[0] eventually I'd like to access the tuple contents in a more descriptive way, for example: print point.x, point.y but instead I have to write (not very legible) print point[