打卡记录
- 学号:1901090022
- 学习课程:Introduction to Computer Science and Programming in Python
- 学习内容:Problem Set 3 (ZIP)
- 打卡天数:D09
作业(Problem 2: Dealing with hands):
Removing letters from a hand (you implement this!)
The player starts with a full hand of n letters. As the player spells out words, letters from the set are used up. For example, the player could start with the following hand: a, q, l, m, u, i, l The player could choose to play the word quail. This would leave the following letters in the player’s hand: l, m.
You will now write a function that takes a hand and a word as inputs, uses letters from that hand to spell the word, and returns a new hand containing only the remaining letters. Your function should not modify the input hand. For example:
1 | >> hand = {'a':1, 'q':1, 'l':2, 'm':1, 'u':1, 'i':1} |
作业心得
作业要求,实现update_hand函数,根据作业中的提示,可以通过 copy 函数来实现次函数的功能。
学习的新函数:
- Python dict.copy 函数: 复制dict,修改新的dict不会影响原来的数据; ceil()
- Python del 函数: 删除 dict 中对应key的项
程序代码
1 | # |