tags:

views:

76

answers:

3

I'm new to Python and am reading a book that came out in 2009 and so uses Python 2.5 syntax. It does the following:

_fields_ = [
    ("cb", DWORD),
    ("lpReserved", LPTSTR),
    ...
]

To me it looks like a list of tuples, but at the same time it feels like a Map/Dictionary. Was this the older syntax?

+3  A: 

No, this was always a list of tuples. That looks like a datatype "mapping" for the purposes of ctypes, but it's just a list, not a real map.

Nick Bastin
+1  A: 

No, that's just a list of tuples. Dictionaries in Python have always used the {} notation.

Greg Hewgill
+2  A: 

It's perfectly good, current syntax, and expresses a list of pairs (two-item tuples). If you need a dict (and have no problem with duplicate keys;-), dict(_fields_) will make you one (much like somedict.items() makes you a list of pairs from a dict -- list(somedict.items()) if you're in Python 3 but insist on getting a list rather than just a view/iterator, btw;-).

Alex Martelli