- 145.5k
- 22
- 190
- 478
Faster way to group email-date pairs by date w/owithout many nested for loops?[python]
Given list of pairs (email-date):
['[email protected]', '2 august 1976'],
['[email protected]', '3 august 2001'],
['[email protected]', '2 october 2001'],
['[email protected]', '2 october 2001'],
['[email protected]', '2 august 2001']]
I need to turn it into dictionary grouped by dates( oneone date ->→ many emails).
I can do it with for loops:
def emails_for_one_date():
for each_entry in email_date_table:
for each_date in each_entry:
current_date_as_key = each_date
for each_entry2 in email_date_table:
list_emails = []
if each_entry[1] == current_date_as_key:
list_emails.append( each_entry[0])
date_for_emails_dict[current_date_as_key] = list_emails
print("------------------- dict here")
print(date_for_emails_dict)
But pythonPython is such a powerful language, I want to know the 'pythonic' way of doing it! I suspect it can be one line.
Faster way to group email-date pairs by date w/o many nested for loops?[python]
Given list of pairs (email-date):
['[email protected]', '2 august 1976'],
['[email protected]', '3 august 2001'],
['[email protected]', '2 october 2001'],
['[email protected]', '2 october 2001'],
['[email protected]', '2 august 2001']]
I need to turn it into dictionary grouped by dates( one date -> many emails)
I can do it with for loops:
def emails_for_one_date():
for each_entry in email_date_table:
for each_date in each_entry:
current_date_as_key = each_date
for each_entry2 in email_date_table:
list_emails = []
if each_entry[1] == current_date_as_key:
list_emails.append( each_entry[0])
date_for_emails_dict[current_date_as_key] = list_emails
print("------------------- dict here")
print(date_for_emails_dict)
But python is such a powerful language, I want to know the 'pythonic' way of doing it! I suspect it can be one line
Faster way to group email-date pairs by date without many nested for loops?
Given list of pairs (email-date):
['[email protected]', '2 august 1976'],
['[email protected]', '3 august 2001'],
['[email protected]', '2 october 2001'],
['[email protected]', '2 october 2001'],
['[email protected]', '2 august 2001']]
I need to turn it into dictionary grouped by dates(one date → many emails).
I can do it with for loops:
def emails_for_one_date():
for each_entry in email_date_table:
for each_date in each_entry:
current_date_as_key = each_date
for each_entry2 in email_date_table:
list_emails = []
if each_entry[1] == current_date_as_key:
list_emails.append( each_entry[0])
date_for_emails_dict[current_date_as_key] = list_emails
print("------------------- dict here")
print(date_for_emails_dict)
But Python is such a powerful language, I want to know the 'pythonic' way of doing it! I suspect it can be one line.
Faster way to group email-date pairs by date w/o many nested for loops?[python]
Given list of pairs (email-date):
['[email protected]', '2 august 1976'],
['[email protected]', '3 august 2001'],
['[email protected]', '2 october 2001'],
['[email protected]', '2 october 2001'],
['[email protected]', '2 august 2001']]
I need to turn it into dictionary grouped by dates( one date -> many emails)
I can do it with for loops:
def emails_for_one_date():
for each_entry in email_date_table:
for each_date in each_entry:
current_date_as_key = each_date
for each_entry2 in email_date_table:
list_emails = []
if each_entry[1] == current_date_as_key:
list_emails.append( each_entry[0])
date_for_emails_dict[current_date_as_key] = list_emails
print("------------------- dict here")
print(date_for_emails_dict)
But python is such a powerful language, I want to know the 'pythonic' way of doing it! I suspect it can be one line