Re: a question on python
All good suggestions here.
As far as counting how many times a specific person is seen (or doing something with a specific value for that person's entry), you would either want a dictionary with the person's name as the entry, and the key being the number of times that name has been encountered, or the key being a list of some values.
Remember to check to see if a dictionary key with the current person's name exists, like this:
names_dict = {}
name = "some name here"
if names_dict.get(name, None) == None: # if we don't have a key in the dict for person yet
# if you are just counting the occurrences
names_dict[name] = 0
names_dict[name] += 1 # add 1 to the value
As mentioned above, if you want to keep track of specific numbers for each name, you'll probably want to use a list for the dict value rather than an integer; instead of setting names_dict[name] to 0, make it a l ist by using [].
If you want to sort your dict (and all you are doing is counting the occurrences of names), you can do the following, continuing from the example above:
from operator import itemgetter
# this returns a list of tuples; the name from the dict is the first item, the value is the second
# from least to greatest
sorted_dict = sorted(names_dict.items(), key=itemgetter(1))
# from greatest to least
sorted_dict = sorted(names_dict.items(), key=itemgetter(1), reverse=True)
Hope this helps
_______________________________________________ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector