Questions tagged [iteration]

Iteration is the repetition of a block of statements within a computer program, usually with mutable state.

Filter by
Sorted by
Tagged with
2
votes
1answer
19 views

Join ArcGIS tables in Python of plant greenness in response to prior month's rainfall

I am using Python 3.8 with ArcGIS Pro 2.5. This code creates a joined table where I match values for plant greenness in the current month with rainfall X number of months into the past. Each loop ...
3
votes
2answers
239 views

Sliding window iteration in Python

I'm creating a small library of Python utilities, and I'd like feedback on a function which allows iterating over an arbitrary iterable in a sliding-window fashion. Relevant parts of ...
1
vote
1answer
54 views

Which solution is good to generate a list without None results from a function? [closed]

I'm relatively new to Python and learned, that function cannot return nothing, not even None. In my application I want to iterate over a list and keep all non-...
-1
votes
0answers
38 views

Best way to optimize multiple search on Lists java

Anyone could help me to optimize this block of code, I already did a bit improvement but since I'm really bad with this kind of algorithms this all I've done so far. Much appreciate if you can explain ...
2
votes
2answers
73 views

Divide the last element in an array of arrays among the remaining elements

The function below is part of an overall chunk of code to partition an array of size M into sub-arrays of size N. The function in question is written to handle the case: what if M isn't divisible by ...
2
votes
3answers
47 views

Flagging system: Check for changing values in a data frame

I've written the following code to check if a value in a data frame changes. I'm looking at the last 5 values. If there was no change at all I want my code to return 1, if a single one (or multiple) ...
2
votes
1answer
195 views

Pandas iteration over rows for features calculation

I have a pandas data frame and I want to calculate some features based on some short_window, long_window and ...
1
vote
2answers
73 views

Reduce time taken for VBA loop when copying multiple sets of input values, performing Excel formula calculations and recording results

My VBA code currently loops for 5,000 iterations and takes about 25 minutes to collect the output data in the Output excel sheet. Is there a way to reduce the time taken for instance by improving the ...
3
votes
1answer
88 views

Extracting mail data out of MS Outlook's generic mailbox

This code extract data from generic mailbox mapped by MS Outlook I failed at recursive iteration in subfolders, so it stays as iterative one. Added ASCII encoding to deal with crazy national symbols ...
4
votes
4answers
2k views

Forming error messages from a multidimensional associative array

I'm working with an input array, which is 3 levels deep, and creating error message strings accordingly in a separate output array. Below is the code. ...
2
votes
2answers
95 views

Listing last 3 items (or all if less than 3) in an ArrayList

Writing a code to return the last 3 items in a list, if the list has 3 or more elements, otherwise return all list items. But the code looks really bad. What is a better way to write the same code? <...
2
votes
1answer
33 views

Merge adjacent occurrences of identical elements in data collection

There is a small programming exercise to merge adjacent identical elements in a collection. Here are two solutions (passing the tests from the exercise). I am asking for review of the first version ...
11
votes
3answers
825 views

Generating sequential alphanumeric values that match a certain pattern

I'm working on generating large volumes of test data for some performance testing. Part of this is going to involve generating a lot of values that represent an "MBI", which is a certain kind of alpha-...
10
votes
4answers
796 views

Shuffling multiple iterators in order

I have a Python function w/ specified functionality, and two proposed approaches - which do you prefer, and why? (performance, simplicity, clarity, etc) (both use ...
7
votes
1answer
223 views

Map unique raw words to a list of code words

Problem Write a function that replaces the words in raw with the words in code_words such that the first occurrence of each ...
3
votes
1answer
147 views

Nested for-loops in xml parsing

I wrote program that reads and processes xml files submitted by external users. The part of the code in question iterates over xml node's children, appends a dictionary - a future row in a table, and ...
5
votes
1answer
779 views

Finding the closest string match for each string in two dataframe columns

I was wondering what's the fastest method to compare similarity between two lists of strings (e.g. two dataframes, documents etc.) using levenshtein distance or other procedures. I am currently using:...
3
votes
2answers
142 views

Challenge: phone keypad to letters - return all possible strings

The challenge: Given a mapping of digits to letters (as in a phone number), and a digit string, return all possible letters the number could represent. You can assume each valid number in the ...
3
votes
3answers
675 views

JavaScript Sort Stack Coding Challenge

A coding challenge to write a function sortStack that receives a stack of integers into ascending order (with largest integers on top) and returns another stack ...
2
votes
1answer
48 views

Traversing two trees until a common value has been found

I am traversing two objects that may share a common ancestor. To make the code small enough to show here, I have changed it into two dictionaries with values. As you can see, ...
3
votes
1answer
64 views

Find a Sum of Particles in A Set of Boxes Given a Number of Rows and Columns

This is a code challenge, from Codewars, the details of the specific challenge in depth can be found here: https://www.codewars.com/kata/magnet-particules-in-boxes/javascript. The summary of it ...
4
votes
2answers
282 views

JSON selector class in Python

I've created a simple little class called JSONSelector to be able to select relevant data from a JSON object (a dict in Python). ...
11
votes
2answers
534 views

Parallelized for loop in Bash

I am using a Bash script to execute a Python script multiple times. In order to speed up the execution, I would like to execute these (independent) processes in parallel. The code below does so: <...
2
votes
2answers
170 views

Iterating over a range of integer ranges in Java

My use case is this: RangeDemo.java: ...
19
votes
5answers
3k views

Count Even Digits In Number

I was asked to complete this CodeStepByStep problem. Here's a quick summary: Write a function named count_even_digits that accepts two integers as parameters ...
5
votes
2answers
163 views

Blackjack game: Count Hand Value method

I am almost completing my BlackJack game in Javascript. But I realize that there must be a way to improve the performance for these two methods. Any pointers? ...
1
vote
1answer
47 views

Check if a web element has a specific property and apply changes to the DOM according to the property's existence

I wrote this Javascript snippet for a Polymer fronted, it works without issues. The only thing that it accomplishes is changing an icon's orientation whenever a user is clicking on any expandable-...
0
votes
1answer
100 views

Grouping objects that have the same attributes

A list of objects needs to be grouped. The list is iterated and checked with other objects in the same list except itself. The method People.isAttributeEqual() checks if two objects can be grouped. ...
3
votes
2answers
146 views

N-Repeated Element in Size 2N Array

The task is taken from leetcode In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeated N times. Return the element repeated N times. ...
2
votes
3answers
100 views

Find non-duplicated integer in a list where every integer occurs three times except for one integer

The task Given an array of integers where every integer occurs three times except for one integer, which only occurs once, find and return the non-duplicated integer. For example, given [6,...
4
votes
1answer
164 views

Walking over a N branching tree

The aim of this code, written in Python3.6, was to write a function that will non-recursively walk over a N-branching tree structure. It works by using a list of indices that keep track of visited ...
2
votes
2answers
73 views

A Java Iterable over multiple arrays

GlueArrays is used for iterating over an array of arrays, and it looks like this: Main.java ...
2
votes
2answers
50 views

Iterating through two objects with different structures in parallel

I have two objects, one input = Array<Type> and one stored = Array<{..., Type}> What's the best (cleanest) way to ...
2
votes
1answer
87 views

Write a function that adds two numbers stored in a linked list and returns the sum

Just for fun I did the following exercise from "Cracking the coding interview. 4th edition": You have two numbers represented by a linked list, where each node contains a single digit. The digits ...
3
votes
3answers
117 views

Check if a postcode is in a list

I'm looking for improvement / advice / reviews on how I can improve this code. I feel like there is a better way or more efficient way of doing this and I am over looking it. The Plugin I made is ...
3
votes
0answers
19 views

IDL code for minimum distance calculation

I made a program in IDL for performing a minimum distance classification on multispectral satellite data. This is what my main function looks like: ...
2
votes
1answer
81 views

Creating objects from xml-data

I've got an XML file with some info about hosts connected to my home network and I would like to create objects containing that info in a neat way, so that I can make some nice front-end application ...
2
votes
0answers
43 views

Speed up iteration for large dataset in python

I'm trying to parse data into a csv prior to a bulk transaction into Neo4j. I'm using vast amounts of data in the relationships and wondered if anyone could help in speeding up the transactions below....
4
votes
2answers
191 views

Zig-zag child element with Flexbox and JavaScript

Recently I found a question on StackOverflow that seemed very interesting: How to make HTML elements "zig zag" this way: ...
2
votes
1answer
150 views

Web scraping JSON-data from API put into Dataframe

The web-scraping process currently takes quite a bit of time, and I wonder if I can structure the code otherwise or improve it in any way. Code looks like this: ...
22
votes
7answers
9k views

FizzBuzz in Javascript

I'm sure everyone here knows what FizzBuzz is. I would like constructive criticism for my solution. I'm a beginner to programming as a whole and this isn't my first solution, but it's what I think is ...
4
votes
3answers
423 views

Java Magic square program

Here is my improved version of my Magic square program from following this earlier version. I also added a few comments. Any help for improvements would be really appreciated. ...
0
votes
1answer
48 views

Generating probability table of 2-character combinations from text file in Java

I have written a probability table generator in Java to help me generate randomized girl's names for the game I am making. It reads from a text file and creates a ...
3
votes
2answers
58 views

Storing statistics as JSON in a simulation game

I am working on a choice-based simulation and players have to choose between different locations, I am pushing those choices to an array locationLog and my ...
2
votes
3answers
94 views

Extracting data in ES6

I have this array const idArray = ["12", "231", "73", "4"] and an object ...
1
vote
6answers
3k views

Elegantly exclude part of an operation for the last iteration in a loop [closed]

I'm afraid just about everybody who read this question has misunderstood it. I'm not trying to find the best way of printing a vector. I'm trying to find the best way of excluding part of an operation ...
2
votes
1answer
35 views

Finding the Original Fractions from Rounded Decimals

The data I'm using is summoning rates from a gacha game, One Piece Treasure Cruise. The game provides the probability of getting a certain character in percents rounded to the nearest thousandth. ...
3
votes
2answers
64 views

Collect members from custom tree nodes

In my program, I have a tree of Group nodes, each identified by their ImportId. Each group has zero or more members, that I ...
3
votes
1answer
66 views

Toggle Event Delegation

NOTE: the Javascript is all I'm concerned about, the HTML/CSS is just DEMO code. One caveat is ARIA states or attributes, if you have input on that, by all means, dive in. I had the need for and ...

1
2 3 4 5