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
3
votes
1 answer

ValueError: too many values to unpack while using torch tensors

For a project on neural networks, I am using Pytorch and am working with the EMNIST dataset. The code that is already given loads in the dataset: train_dataset = dsets.MNIST(root='./data', train=True, …
Emil
  • 1,531
  • 3
  • 22
  • 47
3
votes
1 answer

Why does passing an enumerate function result to the dict constructor yield a type warning?

Consider these two dict declarations: some_data = [4, 5, 6] d1 = dict(enumerate(some_data)) d2 = dict((x, y) for x, y in enumerate(some_data)) The return value of enumerate() is an enumerate object, which I understand to be like a generator (if it…
Grismar
  • 27,561
  • 4
  • 31
  • 54
3
votes
1 answer

Iterating over Numpy Array rows in python even with 1 row / 2 columns array

I am trying to iterate over the rows of a numpy array. The array may consist of two columns and multiple rows like [[a, b], [c, d], ...], or sometimes a single row like [a, b]. For the one-dimensional array, when I use enumerate to iterate over…
EdouardDKP
  • 71
  • 6
3
votes
2 answers

Centering LaTeX tabulars within enumeration/itemize

New to stack overflow, forgive me if I forget to include something... What I'm trying to do is get rid of this space above my centered Table (tabular environment). The problem is that if I do not insert a blank line after the \item, the label gets…
Diegovo
  • 75
  • 1
  • 7
3
votes
4 answers

Using enumerate() to enumerate items with letters rather than numbers

I'm trying to use the built-in function enumerate() to label some points or vertices where each point is represented by its coordinates in a list(or set) of tuples which essentially looks like {(4,5), (6,8), (1,2)} I want to assign a letter starting…
Josh
  • 140
  • 8
3
votes
3 answers

How to determine several minimum in a list?

I have a list with several minimum: some_list = [1,4,6,4,1,7] Is there a built-in function or any smart solution to get the index of the minimums? result = [0,4] I made it like this so far, but I prefer a shorter/easier to read the solution. min…
3
votes
4 answers

Ruby Map Method edits the original array?

def removal(arr) letters ="i" p arr new_array = arr.map do |c_word| c_word.each_char.with_index do |char, index| if letters.include?(char) c_word[index] = "*" end end end …
fr_awd
  • 33
  • 4
3
votes
3 answers

How to use enumerate(zip(seq1,seq2)) in jinja2?

I'm trying to color some sequences of RNA using Django. I'm using enumerate and zip to find equals index in list. for example: for i, (a, b) in enumerate(zip(seq1, seq2)): if a == b and i not in green:

cacotsuki
  • 33
  • 1
  • 4
3
votes
1 answer

Problem with how pop() and enumerate() interact

When I use List.pop inside a for loop that uses enumerate, the process terminates before getting to the end of the list. How do I get around having pop cut short the process? I've checked that if I write the loop using pop but without enumerate,…
fox-daniel
  • 59
  • 1
  • 3
3
votes
2 answers

How would one List the Databases in a SQL Server, not by query, but by c# call?

From this: Enumerate all running databases One can list the servers on the network, but once one selects one of those servers, how does one then list the DB's in that server, by using a similar method as above? Thanks!
user259286
  • 977
  • 3
  • 18
  • 38
3
votes
2 answers

Enumerating dataframe based on a column

I am dealing with a time-series dataframe that looks like this except with more than thousands of rows. I want to make a new column that enumerates the blocks of rows with the same values of 'sign'. i.e. 0th row would be 0, 1st row to 23rd row would…
mathguy
  • 1,450
  • 1
  • 16
  • 33
3
votes
2 answers

Does the enumerate() function count elements in advance?

To support indexing over a collection Python includes enumerate() function. It provides index over collection. for index, item in enumerate(list): # do domething print index In my case I have a huge list and wonder if it is faster to create…
Gunnar Schigel
  • 266
  • 4
  • 10
3
votes
5 answers

Stuck with loops in python - only returning first value

I am a beginner in Python trying to make a function that will capitalize all of the values with an even index, and make lowercase all of the values with an odd index. I have been struggling repeatedly with for loops only giving me the first value.…
hhillman231
  • 125
  • 1
  • 2
  • 9
3
votes
3 answers

C# How to determine if hwnd is in tray icons

I am trying to get the hwnd of the current tray icons. what I did is getting the hWnd of system trat window by using this code: [DllImport("user32.dll", SetLastError = true)] static extern IntPtr FindWindowEx(IntPtr hWndParent, IntPtr…
Ron
  • 3,975
  • 17
  • 80
  • 130
3
votes
3 answers

How do I enumerate a list comprehension with two 'for's?

I am trying to do ls = [myfunc(a,b,i) for a in a_list for b in b_list] but also pass in i into myfunc, which is an index starting at 0 and incrementing for each new element. For example: a_list = 'abc' b_list = 'def' should result in ls =…
siowy
  • 238
  • 1
  • 2
  • 11