# Python 3.7 - Beginner loop and list item help

**URL:** <https://forum.freecodecamp.org/t/python-3-7-beginner-loop-and-list-item-help/320629>\
**Category:** General\
**Created:** [October 9, 2019, 10:32pm UTC](https://forum.freecodecamp.org/t/python-3-7-beginner-loop-and-list-item-help/320629 "2019-10-09T22:32:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul41](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@Paul41](https://forum.freecodecamp.org/u/Paul41)\
**Post date:** [October 9, 2019, 10:32pm UTC](https://forum.freecodecamp.org/t/python-3-7-beginner-loop-and-list-item-help/320629/1 "2019-10-09T22:32:56Z")

</div>

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:

```python

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?

---

<div class="post-metadata">

**Author:** ![ArielLeslie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/arielleslie/32/264841_2.png) [@ArielLeslie](https://forum.freecodecamp.org/u/ArielLeslie)\
**Post date:** [October 9, 2019, 10:34pm UTC](https://forum.freecodecamp.org/t/python-3-7-beginner-loop-and-list-item-help/320629/2 "2019-10-09T22:34:04Z")

</div>

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](http://forum.freecodecamp.com/t/forum-code-formatting/25574) 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.

![markdown_Forums](https://sea3.discourse-cdn.com/freecodecamp/uploads/default/original/3X/4/b/4b9a26f0c243380dd84935f4e29b92e3ecee8d05.gif)

---

<div class="post-metadata">

**Author:** ![Code-Ex](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/code-ex/32/124932_2.png) [@Code-Ex](https://forum.freecodecamp.org/u/Code-Ex)\
**Post date:** [October 9, 2019, 10:35pm UTC](https://forum.freecodecamp.org/t/python-3-7-beginner-loop-and-list-item-help/320629/3 "2019-10-09T22:35:00Z")

</div>

you use index position

---

<div class="post-metadata">

**Author:** ![Code-Ex](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/code-ex/32/124932_2.png) [@Code-Ex](https://forum.freecodecamp.org/u/Code-Ex)\
**Post date:** [October 9, 2019, 10:37pm UTC](https://forum.freecodecamp.org/t/python-3-7-beginner-loop-and-list-item-help/320629/4 "2019-10-09T22:37:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paul41](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@Paul41](https://forum.freecodecamp.org/u/Paul41)\
**Post date:** [October 9, 2019, 11:05pm UTC](https://forum.freecodecamp.org/t/python-3-7-beginner-loop-and-list-item-help/320629/5 "2019-10-09T23:05:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![harshmangal](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/harshmangal/32/124149_2.png) [@harshmangal](https://forum.freecodecamp.org/u/harshmangal)\
**Post date:** [October 10, 2019, 3:04am UTC](https://forum.freecodecamp.org/t/python-3-7-beginner-loop-and-list-item-help/320629/6 "2019-10-10T03:04:28Z")

</div>

```auto
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.

---

<div class="post-metadata">

**Author:** ![programmerguy234](https://avatars.discourse-cdn.com/v4/letter/p/4bbf92/32.png) [@programmerguy234](https://forum.freecodecamp.org/u/programmerguy234)\
**Post date:** [December 12, 2019, 1:32am UTC](https://forum.freecodecamp.org/t/python-3-7-beginner-loop-and-list-item-help/320629/7 "2019-12-12T01:32:41Z")

</div>

Hi!

I found a good code example on this post, [python for loop](https://systemoutofmemory.com/blogs/the-programmer-blog/python-for-loop).

```auto
fruits = ["apricot", "blueberry", "strawberry"]
for x in fruits:
  print(x)
#Output 
apricot 
blueberry 
strawberry

```

I hope this helps! 🙂

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 11:30am UTC](https://forum.freecodecamp.org/t/python-3-7-beginner-loop-and-list-item-help/320629/8 "2021-01-16T11:30:39Z")

</div>

Closed on January 16, 2021, 11:30am UTC


