d = {}
with open("file.txt") as f:
for line in f:
(key, val) = line.split()
d[int(key)] = val
More Related Contents:
- How to name a file using a value in a list in a dictionary?
- How to save a dictionary to a file?
- How to get rid of double backslash in python windows file path string? [duplicate]
- How do I sort a dictionary by value?
- Split / Explode a column of dictionaries into separate columns with pandas
- Is explicitly closing files important?
- Iterating on a file doesn’t work the second time
- Directory-tree listing in Python
- Read and overwrite a file in Python
- Creating a dictionary from a CSV file
- How to implement a pythonic equivalent of tail -F?
- replacing text in a file with Python
- Nested dictionary to multiindex dataframe where dictionary keys are column labels
- How do I call a function from another .py file?
- How to dump a dict to a JSON file?
- Most efficient way to search the last X lines of a file?
- Python: Checking if a ‘Dictionary’ is empty doesn’t seem to work
- 5 maximum values in a python dictionary
- os.walk without digging into directories below
- Subclassing dict: should dict.__init__() be called?
- Extract a subset of key-value pairs from dictionary?
- convert csv file to list of dictionaries
- What is the idiomatic way to iterate over a binary file?
- Error with double backslash in Windows path in Python [duplicate]
- python dict.add_by_value(dict_2)?
- Using Python class as a data container [closed]
- How can I convert string values from a dictionary, into int/float datatypes?
- sorting list of nested dictionaries in python
- How to convert only numbers in a mixed list into float
- In what case would I use a tuple as a dictionary key? [closed]