1

I have been asked at school to explain what the following line of code means.

if any(word in 'variable' for word in list_):

I know what it does but I am having trouble putting it into words. If anyone could give me an explanation I would really appreciate it.

I have found other explanations, however these are too advanced for what I am doing in school. I need the explanation to be simple but it also needs to be detailed at the same time.

My explanation is: for word in list_ searches for each Word in the list and gives it a name, word. For each word we see if word is in the string 'variable'. any() will tell us if one of the words matches.

H14
  • 13
  • 4
  • 1
    Possible duplicate of [How exactly does the python any() function work?](http://stackoverflow.com/questions/16505456/how-exactly-does-the-python-any-function-work) – idjaw Feb 25 '16 at 17:01
  • 1
    Can you show us your attempt to put it into words? Then we can see if you understood it correctly. – Tim Pietzcker Feb 25 '16 at 17:03
  • Please, explain what you are thinking so that it shows you have done at least some efforts! – Dataman Feb 25 '16 at 17:04
  • `for word in list_ searches for each Word in the list ` - it rather iterates or loops, not searches. `any() will tell us if one of the words matches.` - if **at least** one is important here. Otherwise it's pretty good explanation! :) – Yaroslav Admin Feb 25 '16 at 17:15

0 Answers0