2

I'm trying to modify my listt:

listt = [[1, 4], [11, 24], [11123, 6624], [3, 4]]
lvl = 11
n = 50
for z in listt:
    if z[0]==lvl:
        if z[1] > n:
            z[1]=n
        elif z[1] < n:
            z[1]=None

As you can see I'm trying to replace the second number of the position z in listt if lvl is equal to the 1rt number of listt (in the same position) by n.

If the second number is smaller than n I want to assign the position z[1] = "empty"... so it would be like: [...,[11,],...] or something like this, but it's printing this:

11 None
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
noona mun
  • 60
  • 5

1 Answers1

0

Use del z[1] instead:

listt = [[1, 4], [11, 24], [11123, 6624], [3, 4]]
lvl = 11
n = 50
for z in listt:     
    if z[0]==lvl:
        if z[1] > n:
            z[1]=n
        elif z[1] < n:
            del z[1]

Now:

>>> listt
[[1, 4], [11], [11123, 6624], [3, 4]]
Mike Müller
  • 82,630
  • 20
  • 166
  • 161