From 0b5245e2d83453f23e13195ea164a35603c4855a Mon Sep 17 00:00:00 2001 From: Ben Landry Date: Tue, 13 Aug 2019 06:35:13 -0400 Subject: [PATCH] [python3/en] Added enumerate function (#3601) * Added enumerate function * adjusted spacing --- python3.html.markdown | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/python3.html.markdown b/python3.html.markdown index ecdbd932..ef78ce37 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -462,8 +462,19 @@ prints: """ for i in range(4, 8, 2): print(i) -""" +""" +To loop over a list, and retrieve both the index and the value of each item in the list +prints: + 0 dog + 1 cat + 2 mouse +""" +list = ["dog", "cat", "mouse"] +for i, value in enumerate(list): + print(i, value) + +""" While loops go until a condition is no longer met. prints: 0