I'll do this again, just because I like sending email. Very similar to Alan G.'s -- but with the do first, ask forgiveness later
a = ["Joe Smith", "Joe Smith", "Jack Smith", "Sam Love", "Joe Smith"] b = {} for x in a: try: b[x] += 1 except KeyError: b[x] = 1 Access count like this, of course, >>> b["Joe Smith"] 3 >>> Jacob Schmidt ----- Original Message ----- From: "Scott Oertel" <[EMAIL PROTECTED]> To: <Tutor@python.org> Sent: Tuesday, August 23, 2005 1:01 PM Subject: [Tutor] Counting help >I have extracted a list of names, i.e. > > "Joe Smith" > "Joe Smith" > "Jack Smith" > "Sam Love" > "Joe Smith" > > I need to be able to count the occurances of these names and I really > don't have any idea where to begin. > > Any ideas? excuse me this is my first post to this list, I hope I > included enough information. > > > -Scott Oertel > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor