Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Blatant Assignment Help

Name: Anonymous 2009-04-03 3:40

hey /prog/

I'm having some trouble with my python assignment and was wondering if you could offer some help.

The bit i am having trouble with is i have to read a bunch of names from a text file that have values after them and sort them out.

the file looks like this

steve A6 A3 A1
kevin A2 A6
nikki A1 A5 A4

what I'm trying to is sort them into nested lists (dictionaries?) or a better way if you know of one.

eg. list(0) = steve
     steve(1) = A3
     list(2(2) = A5
      etc.

but I have no idea how to go about it, I've got functions to read the files char by char or by line, and then split them at '\n' but I don't know the best way to actually sort them.

thanks for your help.

Name: Anonymous 2009-04-03 3:55

Dunno about Python because I'm not a fag, but I bet this will be helpful.
http://wiki.python.org/moin/HowTo/Sorting

Your nested lists thing will work, but it's kind of dumb to use a list for data of known format. I'm not really clear on what the values after the names are supposed to be. If it's actually a list of values, carry on. If it's some data with a known format, e.g. ((STEVE 555-4541) (MIKE 555-6790)), then a struct or a class or somesuch is generally more appropriate, since it gives a name to each of the values stored in it. Otherwise you end up writing a bunch of accessors like (defun contact-name (contact) (first contact)) (defun contact-number (contact) (second contact)), just to make your code readable and maintainable.

Now, I don't know what facilities Python provides in this regard, so think about it for yourself.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List