All pastes #759501 Raw Edit

Anonymous

public python v1 · immutable
·published 2007-11-03 05:12 UTC
rendered paste body
#######################################################comment: NOTE THIS SECTION IS THE FILE: sample_file.txtBurger Hut:36.32:8.27:9.36Shultzey's:54.08:9.95:3.57Thai Tom:89.37:6.75:4.42Thai-ger Room:92.1:3.66:8.17Fresh Flowers:44.38:11.05:9.11comment: 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 linesprint 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}