[英]iterate through function arguments supposede to be lists python
I try to write a long program in python the first part is:我尝试在 python 中编写一个长程序,第一部分是:
def frequence(entranche):
podium = []
for item in entranche:
scat = len(entranche)
for indice in range (len(entranche)):
if entranche[indice] == item:
scat -= 1
frequence = len(entranche) - scat
podium = podium.append(frequence)
plus_haute_frequence = max (podium)
return(plus_haute_frequence)
print(frequence(("Je suis né dans le béton Coincé entre deux maisons Sans abri sans domicile" ).split()))打印(频率((“Je suis né dans le beton Coincé entre deux maisons Sans abri sans domicile”)。split()))
How would the program treat "entranche" as list?该程序将如何将“entranche”视为列表?
您没有调用split
方法。
entranche = poeme.split()
entranche = poeme.split
is a function, not a list. entranche = poeme.split
是一个函数,而不是一个列表。 You forgot the parenthesis, which do the actual call to the function entranche = poeme.split()
and returns a list.你忘记了括号,它实际调用了函数
entranche = poeme.split()
并返回一个列表。
If entranche
would be a list, you wouldn't see that error.如果
entranche
是一个列表,您就不会看到该错误。 So, check what entranche
really is.所以,检查一下什么是
entranche
。 Check its type()
, or just print
it.检查它的
type()
,或者只是print
它。
You'll find your error here:你会在这里找到你的错误:
entranche = poeme.split
That should be:那应该是:
entranche = poeme.split()
there is noway to precise my question Folowing xph I try this没有办法精确我的问题 以下 xph 我试试这个
def frequence(entranche):
podium = []
print("premier podium", type(podium))
for item in entranche:
print ("deuxieme podium", type(podium))
scat = len(entranche)
for indice in range (len(entranche)):
if entranche[indice] == item:
scat -= 1
frequence = len(entranche) - scat
podium = podium.append(frequence)
print("troisieme podium", type(podium))
plus_haute_frequence = max(podium)
return(plus_haute_frequence)
print(frequence("Je suis né dans le béton Coincé entre deux maisons".split()))
and I get a big surprise!我得到了一个很大的惊喜!
premier podium <class 'list'>
deuxieme podium <class 'list'>
troisieme podium <class 'NoneType'>
What is iT??它是什么??
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.