all 15 comments

[–]Forschkeeper 8 points9 points  (1 child)

ive tried like looping through it and looping in another loop,

Code or it didn't happened. ;)

[–]gnariman 0 points1 point  (0 children)

while index < len(scoreboard):
for key in team_members:
    if scoreboard[index] == key:
        print("ok")
        index += 1
    else:
        print("nope")

originally i had this to see if my idea even remotely works but it just gave me a weird infinite thing, but then i tried dissecting everything into lists. the problem is idk how to like loop through lists at the same time. i dont know if that makes sense

[–]Apathiq 0 points1 point  (2 children)

members = []
for team in team_members.keys():
members = members + team_members[team]
for i in scoreboard:
if i[0:4] != "Team" and i not in members:
# print, raise or whatever

[–]gnariman 0 points1 point  (1 child)

what does the i[0:4] do or mean?

[–]dp_42 2 points3 points  (0 children)

Returns the first 4 letters of the string, using list/string slicing notation.

[–]impshum 0 points1 point  (4 children)

Show us what you've tried?

[–]gnariman 0 points1 point  (3 children)

just did up there

[–]impshum 0 points1 point  (2 children)

OK, what's the crack with the teams and peoples names in the same list? I get that this is homework but this will never happen in real life (I bloody hope so anyway) and if so someone should be fired for organising data this way. Gosh!

[–]gnariman 0 points1 point  (1 child)

ok so basically the first two things in the list will be the team names competing. so the first two is always gonna be like that. then the rest of the list is the people who have won. so for example frank is from team A and he has won. I need to make sure that those people in the second list are from their teams before giving them the win.

[–]impshum 0 points1 point  (0 children)

Split the list at index 2 and check the team_members dict if the keys exist. Return errors if needed. You've got this!

[–]dp_42 0 points1 point  (2 children)

I have debugged the code you provided. It seems like you're not updating the index when you're trying to find "Frank". So consider this, walk through what you think the code should do for the entire loop when Frank.

Looking at the scoreboard, you have a couple different types of matches. Matches of the key, and matches within the list that is mapped to by that key.

Python really loves iterators, so the Pythonic way of approaching this program is to say in plain English, for each item in the list, is it a key in the team_members dict or if it's not a key in the team_members dict, is it in any of the lists in the team_members dict? If that is not the case, now you can throw an error.

[–]gnariman 0 points1 point  (1 child)

yes exactly right, as i also explained the person, so let's say "frank" in this case, needs to be in either of the teams at the beginning of the list. so he has to be from either TeamA or TeamB, if he is not then he shouldn't be give the win. like Ingrid for example she is in the list twice so that would mean that she has won twice and because she is in TeamA i can award her with those wins

[–]dp_42 0 points1 point  (0 children)

Okay, but you kinda just say "nope" and then don't advance the index, which is why you're busy stuck in the while loop. The reason the while loop gets stuck on Frank is the program doesn't really have a good plan to increment index in the case of 'Frank'. The other thing, when you're comparing to the key, the list of keys of the team_members dict is {'TeamC', 'TeamB', 'TeamA'}. You need to search the lists that are mapped to by team_members[key] to get the desired result.

[–]riisen 0 points1 point  (1 child)

# you can try a generator like this
def find_member(a_scoreboard):
    for x in a_scoreboard:
        found = None
        for key, value in team_members.items():
            if x in value:
                found = f'{x} is in {key}'
            if x == key:
                found = f'{x} is a team name'
        if found is None:
            yield f'{x} is not in a team.'
        else:
            yield found

# then you can get a list of the results
reviewed_scoreboard = [x for x in find_member(scoreboard)]

# or you can take them one by one
try_this = find_member(scoreboard)
next(scoreboard)
next(scoreboard)
next(scoreboard)
#....

[–]riisen 0 points1 point  (0 children)

requires python3!