-4

----------------------------------------/

i = 0

x = 00

list1 = [(3000,2,1), (9000,0,8), (4,5,6, 000)]

a = (len(list1))

while (True):

if (x in list1[i]):

    print ( list1[i])

-------------------------------------------------/

This will print: (9000, 0, 8) and (4, 5, 6, 0). This is false result-- How to enforce digit-count or other workaround to avoid this.

Pycharm 2020.2

user176105
  • 19
  • 6

1 Answers1

0

00 and 000 are the exact same as 0, just as 001 and is the same as 1 (I should mention this is in math, not python). You'd need to use strings to keep the leading zeros.

This'll work:

i = 2
x = "000"

list1 = [("3000", "2", "1"), ("9000", "0", "8"), ("4", "5", "6", "000")]

if x in list1[i]:
    print(list1[i])
Missy
  • 13
  • 3