0

im trying to read a csv file in python, then save the contents of csv file into list so that i can then search within that list to see if it matches the input from the user.

here is what i have so far . my code keeps skipping to the else block even if the input matches the number in csv file.

data = []

with open ("numbers.csv", "r") as file:
    reader = csv.reader(file)
    
    for row in reader:
        data.append(row)

if input in data:
   print("success")

else: 
   print("no match")
9090
  • 1
  • 3
    Your [mre] should always include an example of the data. In this case several lines of `numbers.csv`. `if input in data:` - `input` is a built-in python function it is unlikely that function will be in your csv. – wwii Nov 14 '20 at 18:22

1 Answers1

0
import pandas as pd

df = pd.read_csv("file.csv")
data = df.values.tolist()

if input in data:
   print("success")

else: 
   print("no match")
abdulsaboor
  • 678
  • 5
  • 10