Today in this article, we will see How to Access Indexes and element for loop.
The Python interpreter has several functions and types built into it that are always available. Enumerate is one of those built-in functions provided by the Python framework.
- It Returns an enumerated object.
- Here target object that we want to enumerate must have an iterator
- or object supports iteration.
Today in this article, we will cover below aspects,
How enumerate works?
- A tuple contains a count (from the start – defaults to 0, but you are free to set the count on a need basis) and the values.
How to Access Indexes and element for Loop
Example :
urlList = [“url1”, “url2”, “url3”]
for index, item in enumerate(urlList):
content = {
"index": index
"url": item,
"type": "URL_UPDATED"
}
response, content = http.request(ENDPOINT, method="POST", body=json.dumps(content))
print(response)
The above method gives you access to the index and the items from the array of records i.e urlList object simplifying the iterating process effectively.
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.