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

Enumerate in Python variable positions

i'd like to know: what's the difference between these two: return "-".join([c.upper() + c.lower() * i for i,c in enumerate(txt)]) return "-".join([c.upper() + c.lower() * i for c,i in enumerate(txt)]) I just changed the 'i' with the 'c' and the…
-2
votes
1 answer

Python: "int" object is not iteratable in nested enumerate(list)

I am trying to iterate over every element of list b: a = [1, 2, 3, 4] b = [1, 2, 3, 4] for cnt1, a in enumerate(a): print ("a:",cnt1, a) for cnt2, b in enumerate(b): print ("b:", cnt2, b) However, I always get a "TypeError: 'int'…
riggedCoinflip
  • 435
  • 4
  • 16
-2
votes
1 answer

What is the purpose of .enumerated() and .map() in this code?

I'm working a tutorial from https://www.raywenderlich.com/921-cocoa-bindings-on-macos. I'm wondering what the .enumerated() and .map() functions are operating on in this section: @IBAction func searchClicked(_ sender: Any) { guard let…
JamesH
  • 67
  • 6
-2
votes
1 answer

Reverse only numbers from file

How can I reverse only number and not the text from this ? datas.txt Bungo Charlie Bungo Echo Bungo Bravo Bungo Tango Bungo Alpha with open('datas.txt', 'r') as f: for i, line in enumerate(f): print('{}. {}'.format(i+1,…
Logarius
  • 13
  • 5
-2
votes
4 answers

Enumerate a list sorted by two fields in Python

I have an array of this kind: field 4 is the mean of 1,2,3, and field 5 is the min of 1,2,3. [['name0', 24, 19, 25, 22.67, 19], ['name1', 25, 19, 25, 23.0, 19], ['name2', 25, 19, 25, 23.0, 19], ['name3', 24, 22, 23, 23.0, 22], ['name4', 27, 19,…
-2
votes
1 answer

How do I figure out the value which is greater than certain threshold in a matrix?

Assume that I have a matrix: a = [[4,7,2],[0,1,4],[4,5,6]] And I want to get b = [0, 1] c = [[2],[0,1]] b = [0,1] because the inner lists of a at position 0 and 1 contain values that are smaller then 3. c = [[2],[0,1]] because the [2] nd…
wayne64001
  • 399
  • 1
  • 3
  • 13
-2
votes
1 answer

Enumerate all possible swap of two elements of a vector in Java

Let's say we have an array of integers as follows: int[] sol = new int[] {3, 5, 1, 2, 4}; I want to enumerate all the possible arrays that could be obtained when choosing 2 arbitrary elements of the array and swapping them (i.e. if we swap the…
-2
votes
2 answers

Ruby Hash: type casting

I’m trying to get a better grasp on writing in Ruby and working with Hash tables and their values. 1. Say you have a hash: ‘FOO’= {‘baz’ => [1,2,3,4,5]} Goal: convert each value into a string in the ‘Ruby’ way. I’ve come across multiple examples…
thesayhey
  • 938
  • 3
  • 17
  • 38
-2
votes
2 answers

How to structure FOR loop to simplify nested tuple

In a Python script I'm writing, I have a function that can only output its results in a nested tuple, like so: (('foo',), ('bar',), ('baz',), ('spam',), ('eggs',)) I need to structure a FOR loop so that I can use the tuple (as a tuple for…
A. Galloway
  • 135
  • 1
  • 10
-2
votes
1 answer

Find elements of 2 lists in a string in python

list1 = ['abra','hello','cfre'] list2 = ['dacc','ex','you', 'fboaf'] ttext = 'hello how are you?' for i,j in zip(list1, list2): print i,j abra dacc hello ex cfre you None fboaf if (i in ttext and j in ttext): Hello, this compare the same…
super trainee
  • 117
  • 2
  • 11
-2
votes
1 answer

Enumerate table rows in html

I have this code which prints a table taken from a search query and I want to enumerate them using PHP. I'm trying a for loop but unsuccessfully. Can anyone please help me?
thr
  • 35
  • 1
  • 9
-2
votes
2 answers

Python: Find index for word in a text

I have a text: joiskodposkfkfsdpsstopjisjijdjnsndsjijdstopisjidinsindistopskndishf which contains several "stop". I would like to find the index for all locations where "stop" occur. How can I do this? I have tried list but I only seem to get the…
HVO
  • 1
  • 2
-2
votes
1 answer

How does enumerate() method of ThreadGroup works?

The int enumerate(Thread[] list) function updates the specified list[] (of the calling function) with the info about active threads .How is it possible?? The list[] is passed as an argument to the enumerate function without it's reference and the…
AKrish
  • 3
  • 1
-2
votes
1 answer

Trying to use a Nested For Loops w/ 2 variables, Keeping 1 the same while running through the first for loop

Sample data (towers1.txt): MS33 42.19 -70.33 3.6 JS89 42.23 -70.30 3.9 ED22 42.25 -70.33 3.4 HE90 42.27 -70.35 3.7 TW05 42.30 -70.30 3.4 WW23 42.37 -70.28 3.7 Code: lr = [] import lat_long_to_dist f = open('towers1.txt','r') towers =…
-2
votes
2 answers

Ruby .detect alternative

I am looking for an alternative that would solve the following issue: with .detect if I am looking for stringvalue and the value given is 132stringvalue, it will still return true. I need an alternative that will be matching everything from the…
Darko
  • 535
  • 1
  • 6
  • 15
1 2 3
64
65