• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Reading from files and parsing data efficiently

 
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm back! Okay, I've got this text file with a list of data for 85 restaurants. The data is organized for each in this order: name, rating, price range, cuisine type. I am supposed to write a function that reads this file and returns a tuple of three dictionaries. I used file.readlines() to read the file in, then I stripped out all of the \n characters. This left me with list of data separated by an empty string. I created the first dictionary by iterating through the indexes of the file, creating keys and values, but the other two dictionaries involved keys that had lists for values, and I just got stuck, so I populated them manually. I'm sure I'm supposed to create the dictionaries by reading the file, but I haven't been able to come up with code that works. What can I try to build these dictionaries by reading the file? I need a little nudge in the right direction.

Eureka!



This populates my first list. These nested loops require inside-out thinking, and it takes me a while to sort hem out. (That and I used Python Visualizer to step through the code. Nice little tool!)
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See above!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic