1æ¥200éã»ã©ã®ã¹ãã ã¡ã¼ã«ãæ¥ã。ã»ã¨ãã©ã®ã¹ãã ã¡ã¼ã«ã¯ãã£ã«ã¿ã¼ãéãã¦å¦çãããã®ã§å®å®³ã¯å°ãªãã、æ°æã¡ã®è¯ããã®ã§ã¯ãªã。ãµã¨、è¤æ°ã®ã¡ã¼ã«ã¢ã«ã¦ã³ãã使ã£ã¦ãã¦ã©ã®ã¢ã«ã¦ã³ããä¸çªè¢«å®³ãããã®ãã¡ãã£ã¨æ°ã«ãªã£ãã®ã§、ã¡ã¼ã«ã¢ãã¬ã¹ãã¨ã«ã¹ãã ã¡ã¼ã«ãæ°ãä¸ã、æ°ã®å¤ãé ã«è¡¨ç¤ºããPythonããã°ã©ã ãæ¸ãã¦ã¿ã。Pythonããããã¬ã°ã£ã¡ãã³ã¼ããªã®ã§ãã¾ãã³ã¼ãã£ã³ã°ã®åèã«ããªããã¨。 import re def read_spam(fname, pattern): data = [] for d in [[s for s in l.replace(":", " ").replace(" ", " ").strip().rstrip().split()[1:] if not re.search("\"", s) if re.search(".+@.+", s)] for l in file(fname) if re.search(pattern, l)]: data.extend(d) data_counts = {} for d in set(data): data_counts[d] = data.count(d) for d in sorted(data_counts, cmp=lambda x, y: cmp(data_counts[x], data_counts[y]), reverse=True): print "%5d %s" % (data_counts[d], d) æ®æ®µã¯Thunderbirdãå©ç¨ãã¦ãã、ããã©ã«ãã§ã¯ã¹ãã ã¡ã¼ã«ã¯Junkãã¡ã¤ã«ã«è½ã¨ããã。ãã®å ´å、以ä¸ã®ããã«å®è¡ããã°OK。 read_spam("Junk", "^To: ") 以ä¸ã®ããã«è¡¨ç¤ºããã。 4652 [email protected] 3745 [email protected] 2176 [email protected] 1819 [email protected] 686...
Good things. Bad things.