Sure, but it depends on the data. There is no single way to represent key/value pairs in a txt or csv.
Read the file in and split() or parse however you want so you you've got the key and the value.
Then assign them in a loop over each part in the file. A simple one might be something like:
Read the file in and split() or parse however you want so you you've got the key and the value.
Then assign them in a loop over each part in the file. A simple one might be something like:
dictionary = {} with open("foo.csv") as f: for line in f: key, value = f.rstrip().split(",") dictionary[key] = valueYou might need to use the CSV module if you have complex delimiters (Quoted elements, etc.)