Home value of variable is not equal to value in this code
Reply: 1

value of variable is not equal to value in this code

user9191897
1#
user9191897 Published in 2018-01-09 09:02:14Z

in the following code, i have a variable "split_data[i]", i am comparing each element of this variable to a file in "text variable:

    i = 0
    while i < len(split_data):
        print(split_data[i])
        if  split_data[i] in text: #string in present in the text file
            print("Matched" )
        else:
            print("not matched" )    
        i += 1

the value of split_data[4] is '03:31' which is present in the text but still the output is "not matched" whereas if my code is like this:

    i = 0
    while i < len(split_data):
        print(split_data[i])
        if  '03:31' in text: #string in present in the text file
            print("Matched" )
        else:
            print("not matched" )    
        i += 1

the output is matched. or else we can say:

    if '03:31' in split_data[4]:
        print("true")
    else:
        print('false')

is true but

    if '03:31' == split_data[4]:
        print("true")
    else:
        print('false')

is false

this is my whole code :

import mysql.connector
import numpy as np
conn=mysql.connector.connect(user="root", password="",
                             host="localhost", database="videojs")

# prepare a cursor object using cursor() method

def read_from_db():

    cursor = conn.cursor()
    cursor.execute("select time_arr from info where id ='53'")
    data=cursor.fetchone()
    print(data)

    the_new_list = [x.split(',') for x in data]
    print(the_new_list)
    str_data = ''.join(map(str, the_new_list))
    print(len(str_data))
    split_data=str_data.strip('[]').split(',')
    print(split_data)
    print(len(split_data))  

    i = 0
    while i 

please guide me how to resolve this i am a beginner

this is the data in text:

    1
    00:00 --> 00:06
    welcome to your very<font color="#CCCCCC"> first tutorial</font><font 
    color="#E5E5E5"> on</font>

    2
    00:02 --> 00:08
    beginning HTML HTML<font color="#E5E5E5"> is the bedrock</font><font 
    color="#CCCCCC"> of</font>

    3
    00:06 --> 00:10
    <font color="#CCCCCC">the world wide web</font><font color="#E5E5E5"> 
     and if you're going</font>

     4  
     00:08 --> 03:31
    <font color="#CCCCCC">to do anything</font><font color="#E5E5E5"> 
    even</font><font color="#CCCCCC"> in</font><font color="#E5E5E5"> other 
    languages</font>
Poiz
2#
Poiz Reply to 2018-01-09 09:57:41Z

Perhaps you may want to revisit your looping construct.
Consider the Snippet:

text        = "one two three four five"
split_data  = ["one", "two", "three", "four", "five"]

for i in split_data:
    print( "matched" if i in text else "not matched" )
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.243705 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO