+ 1

word filter

words = ["cat", "car", "code", "home", "learn", "fun", "job", "love", "friend", "zoo", "enjoy", "happiness", "family", "goal", "desire"] #your code goes here x=input() for i in words: if x in i: print(i) I donÂŽt understand for what i is standing for. The code is not working if I use any other letter. Could someone please explain it to me. Thanks in advance.

12th Feb 2023, 9:07 PM
Denis Durban
Denis Durban - avatar
7 Answers
+ 10
Denis Durban the variables in *python for loops* like "i", "j" or whatever the name is, are *not* counters. they are so called loop variables. iterating through a list or an other iterable takes one item at a time and assigns it to the loop variable. so we are able to take that item and process it.
16th Feb 2023, 7:36 AM
Lothar
Lothar - avatar
+ 5
'i' is a temporary variable to hold list items in iterations. You can use any name for variable there. It works. For better understand, share your code which is not working, by saving in playground. for i in words: print(i) for j in words: print(j) for k in words : print(k) These 3 statements works same.. Having different temp variable names..
12th Feb 2023, 9:17 PM
Jayakrishna 🇼🇳
+ 2
Jayakrishna 🇼🇳 ah ok got it. Thank you both.
12th Feb 2023, 9:19 PM
Denis Durban
Denis Durban - avatar
0
Mirielle I mean there is the letter i in this code. Example: for i in words. If I change the letter i with any other letter the code does not work anymore. Does i have a special meaning I am missing?
12th Feb 2023, 9:16 PM
Denis Durban
Denis Durban - avatar
0
Mirielle thats exactly what happend. I just started yesterday with coding, I am making so many little mistakes.
12th Feb 2023, 9:23 PM
Denis Durban
Denis Durban - avatar
0
Denis Durban Dear,in for loops,we need a counter to count ,this counter is usually named as I,j,k,... These letters are usable In nested for loops those we need two or more counters
14th Feb 2023, 2:31 PM
Mehdi Eslami
Mehdi Eslami - avatar
0
Hlw
14th Feb 2023, 7:39 PM
Ridhima Sharma
Ridhima Sharma - avatar