kouty
kouty

Reputation: 320

iterate through function arguments supposede to be lists python

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?

Upvotes: 0

Views: 76

Answers (4)

kouty
kouty

Reputation: 320

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??

Upvotes: 0

xph
xph

Reputation: 997

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()

Upvotes: 1

Julien Spronck
Julien Spronck

Reputation: 15433

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.

Upvotes: 1

Daniel Roseman
Daniel Roseman

Reputation: 600059

You didn't call the split method.

entranche = poeme.split()

Upvotes: 1

Related Questions