0

I have a function when I use it outside the class as a function it works perfectly but when I want to use I as a method in a class I get a TypeError massage :
Traceback (most recent call last):
File "H:\python\prototyp_01.py", line 122, in <module>
manupacians.koor(z)
File "H:\python\prototyp_01.py", line 58, in koor
if manupacians.ordna(z)== z:
File "H:\python\prototyp_01.py", line 45, in ordna
new_j = j-1
TypeError: unsupported operand type(s) for -: 'list' and 'int'
My function

def ordna(self,x):
        b = 0
        y = []
        for j in x:
            new_j = j-1
            if new_j<0:
                del new_j
            else:
                y.append(new_j)
                b+=1
        y.append (b)
        y.sort()
        y.reverse ()
        return y

Any suggestions? Thanks

3
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by Mackjan
0

Ya true, x must be of the format [[1,2,3],[4,5,6],[7,8,9]]
so when the first entry is called
new_j = j-1
it would be something like [1,2,3] -1
so it shows an TypeError
Check what x is returning

0

Thank you very much I will check it!

yes it was a list and a tupel lookslike this.

[4, 4, 2] 10
([4, 4, 2], 10)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.