文章目录
- 闯关任务1
- 闯关任务2
闯关任务1
python">class Solution(object):def canConstruct(self, ransomNote, magazine):""":type ransomNote: str:type magazine: str:rtype: bool"""# 创建两个字典,分别统计 ransomNote 和 magazine 中每个字符的数量ransom_count = {}magazine_count = {}# 统计 ransomNote 中每个字符的出现次数for char in ransomNote:if char in ransom_count:ransom_count[char] += 1else:ransom_count[char] = 1# 统计 magazine 中每个字符的出现次数for char in magazine:if char in magazine_count:magazine_count[char] += 1else:magazine_count[char] = 1# 检查 ransomNote 中每个字符是否在 magazine 中出现且数量足够for char, count in ransom_count.items():if magazine_count.get(char, 0) < count:return False return True
闯关任务2
设置断点,并查看res的值:
‘json\n{\n "model_name": "书生浦语InternLM2.5",\n "development_institution": "上海人工智能实验室",\n "parameter_versions": ["1.8B", "7B", "20B"],\n "context_length": "1M"\n}\n
’
可能出现错误的原因:json.loads()解析一个格式错误的JSON 字符串,res的内容被包裹在了一个 Markdown 格式的代码块标记。