- Code: Select all
`def func(a,tup2):`

k=0

x=0

while k<len(a):

while x<len(tup2):

if tup2[x]<a[k]:

a=tuple([a[0:k]])+tuple([tup2[x]])+a[k:]

if tup2[x]>a[k] and tup2[x]<a[k+1]:

a=tuple([a[0:k+1]])+tuple([tup2[x]])+a[k+1:]

x+=1

k+=1

return a

here is a function that I am writing that takes in 2 tuples as the argument. When it reaches the line if tup2[x]<a[k]:, it says TypeError: unorderable types: int() < tuple()

I then did some assert statements, with argument a=(1,23,24)

- Code: Select all
`def func(a,tup2):`

assert a==(1,23,24)

k=0

x=0

while k<len(a):

assert a==(1,23,24)

while x<len(tup2):

assert a==(1,23,24)

if tup2[x]<a[k]:

a=tuple([a[0:k]])+tuple([tup2[x]])+a[k:]

if tup2[x]>a[k] and tup2[x]<a[k+1]:

a=tuple([a[0:k+1]])+tuple([tup2[x]])+a[k+1:]

x+=1

k+=1

return a

The compiler receives an error at the 3rd assertion, meaning that for whatever reason, tuple a lost its value at the inner while loop. What happened? I can't seem to find the cause. And when I did similar assert statements to tup2 and put it in place of the third assertion for tuple a, tup2 retained its value. Any help here? Thanks! (Just focus on this problem, and not on any others unrelated to this that might exist in my code).