rendered paste body#######################################################
comment: NOTE THIS SECTION IS THE FILE: sample_file.txt
Burger Hut:36.32:8.27:9.36
Shultzey's:54.08:9.95:3.57
Thai Tom:89.37:6.75:4.42
Thai-ger Room:92.1:3.66:8.17
Fresh Flowers:44.38:11.05:9.11
comment: file ends here
#######################################################
def file_to_dictionary(file):
lines = {}
i = 0
def read_file (f):
for line in f:
yield line.split(":")
for x in read_file(open('sample_file.txt')):
temp = ''
for y in x:
try:
if float(y):
lines [temp] = float(y.strip())
except ValueError:
temp = y
return lines
print file_to_dictionary (open('sample_file.txt'))
#############################################################################################################################
Result: {'Thai-ger Room': 8.1699999999999999, 'Thai Tom': 4.4199999999999999, "Shultzey's": 3.5699999999999998, 'Burger Hut': 9.3599999999999994, 'Fresh Flowers': 9.1099999999999994}