У меня есть мульти-строки писем, и мне нужно сделать пару вещей:Добавление нескольких строк в один список?
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
... etc
- мне нужно поставить их в один список:
['[email protected]','[email protected]','[email protected]'
..etc]
необходимо выяснить который по электронной почте является самым повторяющимся в этом списке. Вот как я начал свой код, и я надеюсь, что смогу завершить его, с того момента, как я закончил свой код!
fname = raw_input("Enter file name: ") if len(fname) < 1 : fname = "mbox-short.txt" fh = open(fname) lines = [] count = 0 # For next step for line in fh: line = line.rstrip() if not line.startswith("From ") : continue x = line.split() emails = x[1] #print y maxapperence = 0 famous = None for mail in emails: count = emails.count(mail) if count > maxapperence: famous = mail print famous apparence = dict() for mail in set(emails): apparence[mail] = emails.count(mail) print apparence]
вне положенный:
[email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]
Проверить http://stackoverflow.com/questions/2600191/how-can-i-count-the-occurrences-of-a-list-item-in-python – nucleon
Посмотрите на 'collections.Counter' https://docs.python.org/2/library/collections.html – NightShadeQueen