Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. def get_next_person(raw_data):
  2. first_period = raw_data.find('.')
  3. second_period = raw_data.find('.', first_period +1)
  4. person_info = raw_data[:second_period +1]
  5. return person_info, second_period
  6. #print get_next_person(example_input)
  7.  
  8. def get_all_persons_info(raw_data):
  9. persons_info = []
  10. index_of_persons = []
  11. while True:
  12. person_info, second_period = get_next_person(raw_data)
  13. if person_info:
  14. persons_info.append(person_info)
  15. raw_data = raw_data[second_period + 1:]
  16. else:
  17. break
  18. for person in persons_info:
  19. if (person.split()[0]) not in index_of_persons:
  20. index_of_persons.append([person.split()[0]])
  21. return index_of_persons
  22. #print get_all_persons_info(example_input)
  23.  
  24. def get_next_connection(raw_data):
  25. first_period = raw_data.find('.')
  26. second_period = raw_data.find('.', first_period +1)
  27. person_info = raw_data[:second_period +1]
  28. person = [person_info.split()[0]]
  29. first_connection = person_info.find('to') + 3
  30. last_connection = person_info.find('.')
  31. connections = (person_info[first_connection:last_connection]).split()
  32. first_game = person_info.find('play') + 5
  33. last_game = person_info.find('.', first_game)
  34. games = person_info[first_game:last_game].split()
  35. games_list = []
  36. new_games_list = ''
  37. for word in games:
  38. if word[-1] != ',':
  39. new_games_list += word + ' '
  40. else:
  41. for letter in word:
  42. new_word = ''
  43. if letter != ',':
  44. new_word += letter
  45. new_games_list += new_word
  46. games_list.append(new_games_list)
  47. #data_structure = [person] + [connections] + [games_list]
  48. #return data_structure
  49. return games_list
  50. print get_next_connection(example_input)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement