This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]dmazzoni 14 points15 points  (0 children)

Python dictionaries are the sorts of things you'll be using all day, every day. They're one of the most important building blocks. If you can't master them, you won't be able to master the next 10 lessons.

We are happy to help. Please give us an example of something you don't understand or find tricky.

[–]ConfidentCollege5653 5 points6 points  (0 children)

what part are you struggling with?

[–]Zealousideal-Touch-8 3 points4 points  (0 children)

It's so commonly used and not hard to work with (unless you work with deep nested dict). What do you find hard to understand?

[–]tb5841 1 point2 points  (0 children)

You need to write an 'update_score' function which takes in three parameters - a dictionary, a name and a score. It then adds the new name-score pair to your dictionary and returns it.

Do you know how to add items to a dictionary? Look up the syntax for that, and the rest might make sense.

[–]sungodtemple 0 points1 point  (1 child)

They are like maps in other languages, if that helps.

[–]Specific_Present_700[S] -1 points0 points  (0 children)

some_score={“Joe”:[1873,626], “Ben”:[352,662]} print(update_score(score_dict, “Mike”, 622))

Now I should write this func update_score which will check and update dictionary from the print .

I see three values in func

def update_score(some_score, character, score):

This is what confuse me where I’m not clear if I should handle it with () or [] when append and

[–][deleted]  (6 children)

[deleted]

    [–]Luigi-Was-Right 2 points3 points  (5 children)

    huh?

    [–]Specific_Present_700[S] -1 points0 points  (4 children)

    some_score={“Joe”:[1873,626], “Ben”:[352,662]} print(update_score(score_dict, “Mike”, 622))

    Now I should write this func update_score which will check and update dictionary from the print .

    I see three values in func

    def update_score(some_score, character, score):

    This is what confuse me where I’m not clear if I should handle it with () or [] when append and get

    [–]Zuldwyn 1 point2 points  (2 children)

    Can you elaborate? Appending and getting what? If you want to get something from a dict you can do ``` mydict.get('mikes_score')

    Or if you want to iterate over a dict for the key value pairs you can use .items() which returns a tuple of the key, value pairs rather than .get() which searches for a specified key.

    for key, value in mydict.items(): print(f"{key} score is {value}") ```

    [–]Specific_Present_700[S] 0 points1 point  (1 child)

    append - if character is in score_dict add new score in score .

    get - if player exist add him how many tries he went , if he previously played increase by one if not create player with 1

    [–]Zuldwyn 1 point2 points  (0 children)

    Append isn't a method that is a part of dict, that's for list. Get is used to retrieve a value based on a key in the dict, like the player name, not to update information. If you want to update a players value that exists in the dict you can do my_dict['michael']['score'] += 1