crazy99

Beginner pls help me I dont uderstand how to get specific files out fom  a file

Discussion created by crazy99 on Apr 2, 2012
Latest reply on Apr 3, 2012 by Sycosys
Sorry meant to say specific lines out from a file.
Hi I'm trying to build two seperate dictionaries with a file thats arranged in this format.
I need to take the name's reverse it so first name then last name, for the first dictionary I need to take the first name as the key and the other names in the first block as the values, ie, list of strings.
The second dictionary I need to again use the first name as the key ad the group or groups they belong to as the value.
I have figured out how to reverse the names using the comma to split them, however I end up with list of all the names which really doesnt help me seperate them at all.
Im really confusd as to how I can iterate over this to pull out these specific lines and then associate them as keys with other specific lines as values. Especially confused as to how I can get the first name as the key then the folling names as values and then skip the blank line and start again but with the new key.
Any Help would be greatly appreciated.

Text file Format:

Connors, Leah
Flying Club
Connors, Frank
Patterson, Shawn
Patterson, John

Cosmo, Calvin
Sailing buddies
Dodge ball group
Patterson, Shawn
Patterson, Sally

Connors, Frank
Rowing school
Connors, Leah
Connors, Robert

This is what I have so far but I think im really far off.. Please help
    def load_profiles(profiles_file, person_to_friends, person_to_networks):
                  f = open('profiles.txt', 'r')
                  current_line = line
                  previous_line = line - 1
                  next_line = line + 1
                  for line in f:
                      if line.__contains__(','):
                          key = reverse_name(current_line)
                              if not next_line.__contains__(','):
                          try:
                              person_to_networks[key].append(line)
         except KeyError:
                              person_to_networks[key] = [key]""

Outcomes