Matching a number within a number in a python List -


a queryset returned list:

list1=[2856,28564,1245,232856] 

when try find if number exists in above list writing:

num=2856 if num in list1: 

it matches 2856, 25564, , 232856. how can make sure matches 2856 , not rest?

sorry new python, , not find solution. apologies if asking duplicate question.

it not behave suggest. in fact current syntax gives desired output.

>>> list1=[2856,28564,1245,232856] >>> num=2856 >>> if num in list1: ...     print(num) ...  2856 >>> 

this behavior suggesting. note how necessary convert integers strings in case.

>>> list1 = [2856,28564,1245,232856] >>> num = 2856  >>> [x x in list1 if str(num) in str(x)] [2856, 28564, 232856] 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -