-1

I'm trying to find an element inside of a list. I can print the list's elements completely fine. However, as soon as I try to compare an element inside of a list to a value, it never prints found. I'm trying to check for 47, which is in this simplified list.

db_list = [Albus,15,49,38,5,14,47,14,12]

def main():
    check(47)
       
def check(val):     
    for val in db_list:
        if val in row:
            print("found")
  
main()
Vince
  • 109
  • 2
  • 9
  • 1
    this should be made into a minimal reproducible example: in your case, give us the list and the variable that you're trying to find in the list, along with expected output! – Ironkey Oct 06 '20 at 17:09
  • @Ironkey sorry! added the list – Vince Oct 06 '20 at 17:11
  • Please supply the expected [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). Show where the intermediate results differ from what you expected. We should be able to copy and paste a contiguous block of your code, execute that file, and reproduce your problem along with tracing output for the problem points. Adding the list does not close this gap. Since you claim that the problem is in the search, there should be no external input to your MRE: code the list into your prgram. – Prune Oct 06 '20 at 17:13
  • 2
    Just a guess, mayby it loads 47 as a string and you need to check("47") – Lukas Neumann Oct 06 '20 at 17:13
  • are those nested, because that looks like a dataframe to me. e.g. `[["Albus",15,49,38,5,14,44,14,12], ["Cedric",31,21,41,28,30,9,36,44]]` – Ironkey Oct 06 '20 at 17:13
  • [How to debug small programs.](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) | [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/q/25385173/843953) – Pranav Hosangadi Oct 06 '20 at 17:13
  • @LukasNeumann haha you were right. Forgot the "" around 47. Now it is saying found. Thanks so much for correcting my stupid mistake – Vince Oct 06 '20 at 17:16
  • @Vince I made a awnser so you can mark as solved. – Lukas Neumann Oct 06 '20 at 17:20

1 Answers1

2

Your program imported 47 as a string, not a int, so with

check(47)

you only search for the int, you need to use

check("47")

to search for the string.

Lukas Neumann
  • 656
  • 5
  • 18