This for loop should iterate over even 'lines' in my input, as it holds the users name which I would like to place in a dictionary as a key, with a dictionary inside that key. My output does include the information I needed, but also odd lines which I do not want. I'm new to python so I'm still trying to understand syntax. Here's my code:
def get_name(string_input):
split_fullstop = string_input.split('.')
list = [] #creates a list
for line in split_fullstop:
count = 0
if count % 2 == 0: #if count is even
list.append(line.split('is connected to')) #add info to 'list'
count += 1 #increase count
names = {name[0]:{} for name in list}
return names
And here's the output after printing the function:
{'': {}, 'Levi ': {}, 'Bryant ': {}, 'Jennie likes to play Super Mushroom Man, Dinosaur Diner, Call of Arms': {}, 'Olive likes to play The Legend of Corgi, Starfleet Commander': {}, 'Debra likes to play Seven Schemers, Pirates in Java Island, Dwarves and Swords': {}, 'Levi likes to play The Legend of Corgi, Seven Schemers, City Comptroller: The Fiscal Dilemma': {}, 'Walter ': {}, 'Robin ': {}, 'John ': {}, 'Walter likes to play Seahorse Adventures, Ninja Hamsters, Super Mushroom Man': {}, 'Debra ': {}, 'Freda likes to play Starfleet Commander, Ninja Hamsters, Seahorse Adventures': {}, 'Mercedes likes to play The Legend of Corgi, Pirates in Java Island, Seahorse Adventures': {}, 'Ollie ': {}, 'Robin likes to play Call of Arms, Dwarves and Swords': {}, 'Bryant likes to play City Comptroller: The Fiscal Dilemma, Super Mushroom Man': {}, 'Freda ': {}, 'Olive ': {}, 'Mercedes ': {}, 'John likes to play The Movie: The Game, The Legend of Corgi, Dinosaur Diner': {}, 'Jennie ': {}, 'Ollie likes to play Call of Arms, Dwarves and Swords, The Movie: The Game': {}}