Skip to content

Instantly share code, notes, and snippets.

@etigui
Last active January 8, 2020 14:25
Show Gist options
  • Save etigui/98c4699ed51f2a237479960ed15080a8 to your computer and use it in GitHub Desktop.
Save etigui/98c4699ed51f2a237479960ed15080a8 to your computer and use it in GitHub Desktop.
Appending to list in Python dictionary
from datetime import datetime
dico = dict()
dico.setdefault('42', []).append(datetime.now().strftime("%d-%m-%Y %H:%M:%S:%f"))
dico.setdefault('42', []).append(datetime.now().strftime("%d-%m-%Y %H:%M:%S:%f"))
dico.setdefault('777', []).append(datetime.now().strftime("%d-%m-%Y %H:%M:%S:%f"))
dico.setdefault('777', []).append(datetime.now().strftime("%d-%m-%Y %H:%M:%S:%f"))
print(dico)
## Output ##
# {'42': ['08-01-2020 15:23:18:424524', '08-01-2020 15:23:18:424539'],
# '777': ['08-01-2020 15:23:18:424543', '08-01-2020 15:23:18:424545']}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment