Questions tagged [enumerate]

Related to functions or methods that return enumerations or enumerated-types. These can be objects, data types or data structures in which each of the items of a set has a one-to-one correspondence with a set of ordered numbers. An example is the `enumerate()` built-in function in Python.

Related to functions or methods that return enumerations or enumerated-types. These can be objects, data types or data structures in which each of the items of a set has a one-to-one correspondence with a set of ordered numbers. An example is the enumerate() built-in function in Python.

In Python, the function enumerate(sequence, start=0) sequence must be an object which supports iteration. enumerate() returns an enumerate object which consists of tuples containing a count (from start) and the values obtained from iterating over sequence (from the Python Standard Library official documentation)

975 questions
10
votes
3 answers

How to put figure between items on enumerate list?

I have an enumerate list and some items have figures. My code follows below: \begin{enumerate} \item Estado da arte: \item Levantar os requisitos \item Com o microcontrolador \ref{figurametodo3}. \begin{figure}[h!] …
Augusto
  • 3,825
  • 9
  • 45
  • 93
10
votes
2 answers

Why does enumerate execute slower when not specifying the keyword start?

I noticed the following odd behaviour when timing enumerate with the default start parameter specified: In [23]: %timeit enumerate([1, 2, 3, 4]) The slowest run took 7.18 times longer than the fastest. This could mean that an intermediate result is…
10
votes
2 answers

pylint: Using possibly undefined loop variable 'n'

Pylint says W: 6: Using possibly undefined loop variable 'n' ... with this code: iterator = (i*i for i in range(100) if i % 3 == 0) for n, i in enumerate(iterator): do_something(i) print n because if the iterator is empty (for example []) n…
Ruggero Turra
  • 16,929
  • 16
  • 85
  • 141
10
votes
3 answers

Enumerate plots in matplotlib figure

In a matplotlib figure I would like to enumerate all (sub)plots with a), b), c) and so on. Is there a way to do this automatically? So far I use the individual plots' titles, but that is far from ideal as I want the number to be left aligned, while…
Se Norm
  • 1,715
  • 5
  • 23
  • 40
9
votes
1 answer

Enumerate registry subkeys in delphi

I'm attempting to install a driver on a client machine based on which version of MySQL is installed on the server and to do that I'd like to check the version on the server via registry key. That said, I need to enumerate the subkey(s) of…
Aaron
  • 896
  • 3
  • 11
  • 22
9
votes
3 answers

How can I enumerate an infinite sequence of integers in C# 4.0?

Is there a function in C# that returns an IEnumerator of the infinite sequence of integers [0, 1, 2, 3, 4, 5 ...]? I'm currently doing Enumerable.Range (0, 1000000000).Select (x => x * x).TakeWhile (x => (x <= limit)) to enumerate all squares up to…
Jeremy
  • 1
  • 85
  • 340
  • 366
9
votes
1 answer

How to enumerate a slice using the original indices?

If I want to enumerate an array (say for a map() function where I would need to use the index of an element together with its value), I could use enumerate() function. E.g.: import Foundation let array: [Double] = [1, 2, 3, 4] let powersArray =…
0x416e746f6e
  • 9,872
  • 5
  • 40
  • 68
9
votes
6 answers

pythonic way to associate list elements with their indices

I have a list of values and I want to put them in a dictionary that would map each value to it's index. I can do it this way: >>> t = (5,6,7) >>> d = dict(zip(t, range(len(t)))) >>> d {5: 0, 6: 1, 7: 2} this is not bad, but I'm looking for…
AnalyticsBuilder
  • 4,111
  • 4
  • 24
  • 36
9
votes
2 answers

C# List all "leaf" subdirectories with EnumerateDirectories

Good morning all, I have a folder which contains thousands of subdirectories at different depths. I need to list all of the directories which don't contain subdirectories (the proverbial "end of the line"). It's fine if they contain files. Is there…
Sam2S
  • 165
  • 1
  • 6
8
votes
2 answers

Basic python file-io variables with enumerate

New to python and trying to learn the ropes of file i/o. I am working with pulling lines from a large (2 million line) file in this format: 56fr4 4543d 4343d 5irh3 Here is the function I'm using to return a code: def getCode(i): with…
some1
  • 2,447
  • 8
  • 26
  • 23
8
votes
1 answer

Enumerating files in an embedded resource directory

Is there a way, in WPF, to enumerate through all files within a specific embedded resource directory? That is, a directory of items all having a "Build Action" set to "Resource".
Jordan
  • 9,642
  • 10
  • 71
  • 141
8
votes
1 answer

listing all subsets of a vector for a given size

The function choose(n,k) tells us how many subsets of size k exists for a set of n distinct elements. Suppose I need to actually list those subsets, how I create it? in other words I'm looking for a function that accepts a vector x (of length n) and…
amit
  • 3,332
  • 6
  • 24
  • 32
8
votes
1 answer

Does enumerate create a copy of its argument?

If I use enumerate while iterating through a very large list of graph clusters, I want to make sure I'm not unnecessarily creating any copies of this list in memory. I've been trying to confirm that it will not create any copies, but would like to…
punkrockpolly
  • 9,270
  • 6
  • 36
  • 37
8
votes
3 answers

Most Pythonic for / enumerate loop?

I have a loop condition: for count, item in enumerate(contents): but only want to use the first 10 elements of contents. What is the most pythonic way to do so? Doing a: if count == 10: break seems somewhat un-Pythonic. Is there a better way?
Dirk
  • 3,073
  • 4
  • 31
  • 36
8
votes
6 answers

How can I keep track of (enumerate) all classes that implement an interface

I have a situation where I have an interface that defines how a certain class behaves in order to fill a certain role in my program, but at this point in time I'm not 100% sure how many classes I will write to fill that role. However, at the same…
cheshirekow
  • 4,797
  • 6
  • 43
  • 47
1 2
3
64 65