On 11/23/2011 8:04 AM, Cranky Frankie wrote:
In playing around with Pyton 3 dictionaries I've come up with 2 questions

1) How are duplicate keys handled? For example:

Qb_Dict = {"Montana": ["Joe", "Montana", "415-123-4567",
"joe.mont...@gmail.com","Candlestick Park"],
"Tarkington": ["Fran", "651-321-7657", "frank.tarking...@gmail.com",
"Metropolitan Stadidum"],
"Namath": ["Joe", "212-222-7777", "joe.nam...@gmail.com", "Shea Stadium"],
"Elway": ["John", "303-9876-333", "john.el...@gmai.com", "Mile High Stadium"],
"Elway": ["Ed", "303-9876-333", "john.el...@gmai.com", "Mile High
Stadium"],
"Manning": ["Archie","504-888-1234", "archie.mann...@gmail.com",
"Louisiana Superdome"],
"Staubach": ["Roger","214-765-8989", "roger.staub...@gmail.com",
"Cowboy Stadium"]}

print(Qb_Dict["Elway"],"\n")                        # print a dictionary entry

In the above the "wrong" Elway entry, the second one, where the first
name is Ed, is getting printed. I just added that second Elway row to
see how it would handle duplicates and the results are interesting, to
say the least.

Seems like you answered your first question. Dictionaries do not have duplicate keys. Your 2nd assignment using the key "Elway" replaced the first.

2) Is there a way to print out the actual value of the key, like
Montana would be 0, Tarkington would be 1, etc?
Actual value? The actual value of Montana" is "Montana". Sounds like you want the index of the entry as though it were in a list. Dictionaries are not ordered so you can't get that unless you store it as part of the value.

--
Bob Gailer
919-636-4239
Chapel Hill NC

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to