iteration Questions

4

Solved

Is there any "pythonic" way to do this? I am pretty sure my method is not good: sample = "This is a string" n = 3 # I want to iterate over every third element i = 1 for x in sam...
Helenahelene asked 1/7, 2018 at 9:9

6

Consider something like... for (int i = 0; i < test.size(); ++i) { test[i].foo(); test[i].bar(); } Now consider.. for (int i = 0; i < test.size(); ++i) { test[i].foo(); } for (int i = ...
Ambroseambrosi asked 24/10, 2010 at 2:50

8

Solved

On Python, range(3) will return [0,1,2]. Is there an equivalent for multidimensional ranges? range((3,2)) # [(0,0),(0,1),(1,0),(1,1),(2,0),(2,1)] So, for example, looping though the tiles of a r...
Felipa asked 10/4, 2012 at 17:15

10

I have a question on my homework for class and I need to know how to return nth number of Fibonacci sequence using iteration (no recursion allowed). I need some tips on how to do this so I can bet...
Apprentice asked 22/10, 2012 at 19:20

11

In java if I am looping over the keySet() of a HashMap, how do I (inside the loop), get the numerical index of that key? Basically, as I loop through the map, I want to be able to get 0,1,2...I fi...
Sullins asked 21/4, 2010 at 19:49

3

Solved

I would like to use some iteration control flow to simplify the following LaTeX code. \begin{sidewaystable} \caption{A glance of images} \centering \begin{tabular}{| c ||c| c| c |c| c|| c |c| ...
Cultivar asked 1/4, 2010 at 16:3

46

Solved

If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map? Will the ordering of ...
Pesek asked 5/9, 2008 at 21:12

4

Solved

I need to know when a Queue is closed and wont have more items so I can end the iteration. I did it by putting a sentinel in the queue: from Queue import Queue class IterableQueue(Queue): _se...
Jorgensen asked 2/7, 2012 at 5:26

28

Solved

I have the following code to do this, but how can I do it better? Right now I think it's better than nested loops, but it starts to get Perl-one-linerish when you have a generator in a list compreh...
Carchemish asked 29/6, 2009 at 20:16

16

Solved

In my script I need to perform a set of actions through range of dates, given a start and end date. Please provide me guidance to achieve this using Java. for ( currentDate = starDate; currentDate...
Strappado asked 26/12, 2010 at 18:22

5

I would like to do something like this: for (int p : colourPos[i+1]) How do I skip the first iteration of my colourPos vector? Can I use .begin() and .end()?
Gib asked 3/9, 2014 at 19:46

10

Solved

In Java, what would the fastest way to iterate over all the chars in a String, this: String str = "a really, really long string"; for (int i = 0, n = str.length(); i < n; i++) { char c = str.c...
Emelia asked 17/1, 2012 at 12:2

2

Solved

I have a code base with mixed Java and Groovy code. For iteration in the Groovy code, we tend to use closures: String[] strings = ["First", "Second", "Third"] strings.each { string -> println ...
Hilarius asked 11/3, 2013 at 9:13

2

Solved

in SICP Section 1.2.1 The author giving such a code example below to show how to using iterative process to solve the factorial problem: (define (factorial n) (fact-iter 1 1 n)) (define (fact-ite...
Blowbyblow asked 22/6, 2013 at 18:54

6

Solved

How can I iterate through items of a LinkedHashSet from the last item to the first one?
Shuttle asked 24/5, 2012 at 16:51

16

Solved

In the question Iterate a list as pair (current, next) in Python, the OP is interested in iterating a Python list as a series of current, next pairs. I have the same problem, but I'd like to do it ...
Charliecharline asked 12/8, 2015 at 18:55

9

Solved

I have noticed very poor performance when using iterrows from pandas. Is it specific to iterrows and should this function be avoided for data of a certain size (I'm working with 2-3 million rows)? ...
Silence asked 21/7, 2014 at 17:19

6

Solved

The past few weeks I have been learning about iterators. I still do not understand the main difference between iterating through a link list and traversing through one. I know that traversing means...
Esdraelon asked 1/5, 2013 at 22:24

10

Solved

I just had a quick question regarding loops in Ruby. Is there a difference between these two ways of iterating through a collection? # way 1 @collection.each do |item| # do whatever end # way 2 ...
Daytoday asked 20/7, 2010 at 21:28

19

Solved

I want to cycle through the objects contained in an array and change the properties of each one. If I do this: for (var j = 0; j < myArray.length; j++){ console.log(myArray[j]); } The conso...
Stormi asked 18/5, 2013 at 16:50

6

Solved

I'm looking for ways to interrupt iteration of an infinite iterator. I found that try_fold accomplishes my objective. However, that requires doing the awkward thing of returning an Err on the succe...
Audiology asked 4/9, 2021 at 10:19

1

I am evaluating successive terms of the look and say sequence (more about it here: https://en.wikipedia.org/wiki/Look-and-say_sequence). I used two approaches and timed them both. In the first app...
Pastose asked 4/7, 2018 at 23:13

8

Solved

I have some C++ code, in which the following enum is declared: enum Some { Some_Alpha = 0, Some_Beta, Some_Gamma, Some_Total }; int array[Some_Total]; The values of Alpha, Beta and Gamma ar...
Actinomycosis asked 18/8, 2009 at 7:55

8

Solved

I want to replace the values (formated as strings) with the same values as integers, whenever the key is 'current_values'. d = {'id': '10', 'datastreams': [{'current_value': '5'}, {'current_value'...
Negotiable asked 16/4, 2019 at 9:21

3

In my main coroutine, I am removing or adding entries from a table depending on user operations. In the background, I'd like to iterate over the entries in the table. I don't mind particularly if I...
Folacin asked 29/5, 2011 at 11:41

© 2022 - 2025 — McMap. All rights reserved.