Python 3.7 - Beginner loop and list item help

Python 3.7 - Beginner loop and list item help
0

I’m just learning python and working with lists and some loops. In terms of debugging my code I was trying to figure out what list item would be present and to return it. The code is checking each letter in the string and will output that letter if it is in the list. I know this can be done in other ways.

Code is below:


String = ‘test’
List = [‘1’, ‘a’, ‘e’]

For Letter in string:
      If Letter in list:
           Print(list)

In this case I want to print the letter e, I get an error if put list and the full list as the code is.

My intention is not to actually print this but for debugging only to see the value. The actual code will simply continue if character exists. Is this possible to do?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

you use index position

example:
Strings = ‘test’
List=[‘1’, ‘a’, ‘e’]
for Letter in String:
print(Letter[1])

Thanks will use formatter next time, because it’s in a loop, I want to figure out what iteration of the loop so don’t want to simply enter a specific index value such as 1. I am not sure if there is possibly a way to modify to show loop iteration number that way it will display the letter as it will take that as the index.

String = ‘test’
List = [‘1’, ‘a’, ‘e’]

for Letter in String:
      if Letter in List:
           print(list)

You didn’t took care of case of letters
Hope this helps.