Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python to check if list of int contains in data with ~

I have a list and item like below and want to check if any int in the item contains value ~1~20448~3~22901~12214~27681~9920408~20013~19957~19993~ ~ ~ ~ ~ ~ we should get 1 else 0.

       my_list = ['4587','9920408','9920316']
       flag=0
       value=""
       for item in my_list:
            if '~1~20448~3~22901~12214~27681~9920408~20013~19957~19993~ ~ ~ ~ ~ ~' in item and flag==0:
                 value == 1
            else:    
                 value == 0

Here in the list we have 9920408 and we have that value in the item and the output should be 1 .
But i am getting the below value.

      False
      False
      False

Could you please advise on this. Appreciate your support.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use the tools Python provides:

my_list = ['4587','9920408','9920316']
st = '~1~20448~3~22901~12214~27681~9920408~20013~19957~19993~ ~ ~ ~ ~ ~'
if any( m in st for m in my_list ):
    print( "One of them was found." )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading