Skip to content

Instantly share code, notes, and snippets.

@philippbayer
Created April 17, 2012 02:20
Show Gist options
  • Save philippbayer/2402987 to your computer and use it in GitHub Desktop.
Save philippbayer/2402987 to your computer and use it in GitHub Desktop.
Python dictionary with try/except
return_dict = {}
for line in file_handle:
line_list = line.split()
try:
return_dict[line_list[0]].append(line_list)
except KeyError:
return_dict[line_list[0]] = [line_list]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment