A little morning puzzle

Dwight Hutto dwightdhutto at gmail.com
Mon Sep 24 19:13:39 EDT 2012


The posted code produces neither a set nor any keys;
> it prints out the same predetermined non-key value multiple times.

This shows multiple dicts, with the same keys, and shows different
values, and some with the same, and that is, in my opinion what the OP
asked for:

a = {}
a['dict'] = 1

b = {}
b['dict'] = 2

c = {}
c['dict'] = 1

d = {}
d['dict'] = 3

e = {}
e['dict'] = 1


x = [a,b,c,d,e]
count = 0
collection_count = 0
search_variable = 1
for dict_key_search in x:
        if dict_key_search['dict'] == search_variable:
                print "Match count found: #%i = %i" % (count,search_variable)
                collection_count += 1
        count += 1
print collection_count



The OP can jump in and tell me to alter the example, if they want to.




-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com



More information about the Python-list mailing list