I try to write a long program in python the first part is:
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()))
How would the program treat "entranche" as list?
您没有调用split
方法。
entranche = poeme.split()
entranche = poeme.split
is a function, not a list. You forgot the parenthesis, which do the actual call to the function entranche = poeme.split()
and returns a list.
If entranche
would be a list, you wouldn't see that error. So, check what entranche
really is. Check its type()
, or just print
it.
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
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??
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.