Martin Broadhurst

Search
Skip to content
  • Martin Broadhurst

Accessing the loop index in Python

July 31, 2016 martin

You can get access to the loop index in Python by using the enumerate() function to loop over your iterable:

for index, value in enumerate(['spam', 'eggs', 'ham']):
    print index, value

Reference: PEP 279 – The enumerate() built-in function

Python

Post navigation

Previous PostC++ stream synchronizationNext PostMove semantics in C++

Tags

Algorithms Backtracking Binary Tree Boost C C++ C++11 Combinatorial Algorithms Constructor CSharp Data Structures Depth FIrst Search DFS Dictionary Divide-and-Conquer Dynamic Programming FIles Folly Graph Theory Greedy Algorithms HTTP Iterators Java Knapsack Linked List Linux List Mathematics Network Programming NP-Complete Parsing Permutations Python Recursion Selenium Servers Sockets Sorting STL Strings Templates Threads TSP vector Windows

Recent Posts

  • Selenium Howtos
  • How to get the style of an element in Selenium
  • How to execute JavaScript in Selenium
  • How to get the current contents of a form text element in Selenium
  • How to get an attribute of an element in Selenium

Recent Comments

  • What is a simple C or C++ TCP server and client example? [closed] – inneka.com on Server examples
  • ioQQ编程网 c/c++分割字符串 on How to split a string in C++
  • A server cluster for static files – Blog SatoHost on Consistent hash ring
  • Using Kinesis and Kibana to get insights from your data - Import.io on Consistent hash ring
  • STL iterator invalidation rules – keep learning 活到老学到老 on Iterator invalidation rules for C++ containers

Archives

  • October 2019
  • May 2018
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • April 2016

Categories

  • Uncategorized

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
Proudly powered by WordPress