As of May 31, 2023, we have updated our Code of Conduct.
39 votes
Accepted

Count all vowels in string

An alternative route is to use string.replace() and Regular Expressions to strip everything but the vowels from the string. Then count the length of the resulting ...
Joseph's user avatar
  • 25k
32 votes

Extension method replacing elements from an IEnumerable<T> collection

Why didn't Microsoft include this in the .NET framework? Probably because it can be realized in one line with Select: ...
JanDotNet's user avatar
  • 8,528
28 votes

Count all vowels in string

I'm just wondering if there's an easier way to solve this problem without the big blocky code in the if statement. Well, you could put all of those in an array: <...
Sᴀᴍ Onᴇᴌᴀ's user avatar
25 votes

Pythonish integer range in Java

If you're targeting Java 8, then you should make an IntStream and a PrimitiveIterator.OfInt instead. You can do more ...
200_success's user avatar
25 votes
Accepted

Extension method replacing elements from an IEnumerable<T> collection

I cannot comment about the speed because I didn't benchmark it but there are two obvious improvements. add an IEqualityComparer<T> as a third parameter so ...
t3chb0t's user avatar
  • 44k
20 votes

StreamIterable - create an iterable from a Java 8 Stream

You should not need a special class for this. Method references can be cast to functional interfaces. In this particular case, however, remember that the stream returned by ...
Christopher Currie's user avatar
18 votes
Accepted

Determine added, removed and kept items between two lists

First, let's look at the naive implementation using sets: ...
Graipher's user avatar
  • 40.7k
17 votes
Accepted

Basic iterator supporting vector implementation

The range-based for loop This works via the begin() and end() functions. So for any class <...
Martin York's user avatar
  • 93.3k
17 votes
Accepted

Zipping two lists with an offset in Python

You're on the right track, but it can be simplified to the following. Note also that the step variable name could add confusion because Python ranges and slices ...
FMc's user avatar
  • 11.8k
15 votes

Flags on steroids

I'm not going to say I'd use this, nor that I wouldn't. I think it's a clever1 use of generics, and turns C# enums into something else that could possibly be called ...
Mathieu Guindon's user avatar
15 votes
Accepted

Merge n sorted iterators

There are no docstrings. What do these functions do? What arguments do they take? What do they return? Decorators are normally named after the effect they have on the decorated function. For example <...
Gareth Rees's user avatar
  • 49.5k
15 votes

Counting elements meeting a predicate in an enumerable without iterating the entire sequence

You can use the Linq Take to accomplish the same thing ...
CharlesNRice's user avatar
  • 4,253
15 votes
Accepted

Input Iterator implementation

Input iterator is an abstract concept I think you are very confused. “Input iterator” is a concept. A concept is an abstract specification, not a concrete “thing”. You can’t make an “implementation of ...
indi's user avatar
  • 9,621
14 votes

"Zip-like" functionality with C++11's range-based for-loop

There are a few serious things that haven't been brought up by the other two answers yet. Dereferencing issues Let's say I am zipping a vector<T> and a <...
Barry's user avatar
  • 18.4k
14 votes
Accepted

Pythonish integer range in Java

Minor point. The step is zero is an odd error message. Wouldn't it be better to actual explain the problem, ie. The step cannot be zero The user (hopefully) knows what paramaters they've ...
SuperBiasedMan's user avatar
13 votes
Accepted

StackList<T> implementation

Issues public void Push(T item) { _stackList.Insert(0, item); } The hurts the stack list. It would be much easier if you just added new items at the end of ...
t3chb0t's user avatar
  • 44k
13 votes
Accepted

Sorting algorithm, possibly a new one

Algorithm What you have implemented is called (linear) insertion sort. It is very old, sorry your method is not new or novel ;) It has average case O(n^2) time complexity which is basically unusable ...
Emily L.'s user avatar
  • 16.5k
13 votes

Zipping two lists with an offset in Python

Using itertools.tee to zip an iterable with itself Since you are iterating twice on the same iterable, one possibility is to use ...
Stef's user avatar
  • 240
12 votes

Streaming int support

After reading the problem description and before reading your code, I implemented something that was very similar to what you already have, which means that your approach to the problem is perfectly ...
Simon Forsberg's user avatar
12 votes
Accepted

random_iterator in C++

Naming First of, what you have created is not an iterator so naming it as such is misleading. I would recommend a name but I actually think that you should redesign your class and the name I would ...
Emily L.'s user avatar
  • 16.5k
12 votes
Accepted

Counting elements meeting a predicate in an enumerable without iterating the entire sequence

There are so many different solutions already that I won't post another. But there is something else that bothers me, the names of the extensions. I find they are too confusing. Expecially ...
t3chb0t's user avatar
  • 44k
12 votes

Basic iterator supporting vector implementation

Use delete[] You are allocating an array of objects with new[], but attempting to delete them with ...
cariehl's user avatar
  • 857
12 votes
Accepted

Decoding assembly instructions in a Game Boy disassembler

I have some ideas about how you might be able to improve your program. Avoid problems Rather than trying to deal with the problem for every instruction, one approach is avoiding it entirely. One ...
Edward's user avatar
  • 65k
12 votes

Convert Rankine temperatures to Celsius

Let the caller handle iterables I think allowing an iterable is a bad idea. The caller can already use map(Rankine.to_celsius, temps) or the like with your first ...
Richard Neumann's user avatar
11 votes
Accepted

Table of Tribonacci sequence using NumPy and PANDAS

You’re using the wrong tool for the job. Basically, you do all the computation in Python, use numpy for intermediate storage and ...
301_Moved_Permanently's user avatar
11 votes
Accepted

Multi-dimensional container using operator[]

This would be much easier to review if there were more useful comments (saying "forward declarations" in front of a bunch of forward declarations is not all that useful) or - more importantly - some ...
indi's user avatar
  • 9,621
11 votes
Accepted

Take a desired string, iterate through objects to see if it exists in a given field and append a number until a unique string is found

There's certainly room for improvement. Move that that Select(stringFieldFunction).ToList() out of the while loop. Iterating an ...
Pieter Witvoet's user avatar
10 votes

C++ Array with iterators

Using using namespace std; Don't. See here: Why is "using namespace std" considered bad practice. Exception Handling ...
Emily L.'s user avatar
  • 16.5k
10 votes
Accepted

Input iterator in C++

Correctness Issues Needs dereferencing operator There are two basic operations every iterator needs to support: Incrementing the iterator Dereferencing the iterator Right now, you've covered ...
Jerry Coffin's user avatar
  • 33.3k
10 votes
Accepted

Merge Sort implemented using iterators

Naming sub_merge is weird, as it doesn't match up at all with the meaning of the english word "submerge". I get its origin ("subroutine merge"), but why not simply ...
hoffmale's user avatar
  • 6,448

Only top scored, non community-wiki answers of a minimum length are eligible