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 ...
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:
...
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:
<...
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 ...
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 ...
18
votes
Accepted
Determine added, removed and kept items between two lists
First, let's look at the naive implementation using sets:
...
18
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
...
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 <...
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 ...
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 <...
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
...
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 ...
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 <...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
12
votes
Basic iterator supporting vector implementation
Use delete[]
You are allocating an array of objects with new[], but attempting to delete them with ...
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 ...
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 ...
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 ...
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 ...
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 ...
10
votes
Accepted
Filtered Iterator
Correctness
You can't support remove() because your iterator must always be at least one step behind the iterator being wrapped.
Design
You twist the code to make a ...
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 ...
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 ...
10
votes
Accepted
Iterator for traversing a tree [v2]
My problem with this iterator is that it is very expensive to copy; as you have to copy a stack when you copy the iterator.
The main point of iterator is that it should be "cheap" to make copies. All ...
10
votes
Accepted
Manipulating list values in python
This may be a good case for generator functions. And splitting it into two parts might make things more flexible: first, remove the stopwords; and second, handle the punctuation.
Also, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
iterator × 426c++ × 156
c# × 71
python × 66
java × 62
c++11 × 34
algorithm × 31
performance × 30
python-3.x × 26
linked-list × 25
javascript × 23
beginner × 23
array × 21
rust × 21
c++17 × 21
generator × 20
collections × 17
iteration × 16
reinventing-the-wheel × 15
ecmascript-6 × 15
template × 15
object-oriented × 14
strings × 14
c++14 × 14
tree × 13