Created
April 17, 2012 02:20
-
-
Save philippbayer/2402987 to your computer and use it in GitHub Desktop.
Python dictionary with try/except
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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