selfteaching / selfteaching/selfteaching-python-camp
Day09 if n >= size: TypeError: '>=' not supported between instances of 'list' and 'int'
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 151
- Forks
- 875
- PR merge metrics
- No merged PRs in 30d
Description
Dear all and 吾厘宇宙万能@realcaiying
在day9的作业中,为三个函数添加一个int类型变量count,用于限制元素的输出的个数。
我的思路是在counter objects 支持的method-- .most_common([n])中将int() value的count替换n使用。
type(count) == int #count类型检测为int
然后count数值不要大于对象的长度数值。
然后不是应该workable么?。。。然而故事不是酱婶儿d。。。
报错像图示内一样。
“”“if n >= size:
TypeError: '>=' not supported between instances of 'list' and 'int'”“”
Oh my! 谁在路边方便时打捞一下喵。。。
我的代码如下:
count = 10 [# must add this variable, otherwise it raised "TypeError:'>=' not supported between instances of 'list' and 'int'"]
def stats_text_en (en):
''' 英文词频统计 '''
if type(en) == str and type(count) == int:
text_en = re.sub("[^A-Za-z]", " ", en.strip())
enList = text_en.split( )
count <= len(enList)
return collections.Counter(enList).most_common([count]) # day9 using 1 counter objects supported method -most_common([n])
else:
print("Inappropriate argument value (of correct type)")
def stats_text_cn (cn):
''' 汉字字频统计 '''
if type(cn) == str and type(count) == int:
cnList = re.findall(u'[\u4e00-\u9fff]+', cn.strip())
cnString = ''.join(cnList)
count <= len(cnString)
return collections.Counter(cnString).most_common([count])
else:
print("Inappropriate argument value (of correct type)")
def stats_text(text_en_cn):
''' 合并英汉词频统计 '''
if type(text_en_cn) == str and type(count) == int:
return (stats_text_en(text_en_cn)+stats_text_cn(text_en_cn))
else:
print("Inappropriate argument value (of correct type)")

Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the pasted stats_text_en, stats_text_cn, and stats_text functions and reproduce the reported TypeError using the shown count value. Check how count is passed to the Counter call and how each function limits output. Done means the three functions accept the requested count without the reported error and retain their stated English, Chinese, and combined frequency outputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100