Skip to main content
Share Your Experience: Take the 2024 Developer Survey
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
  • 25.1k
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,538
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
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
  • 44.3k
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
  • 41k
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 ...
FMc's user avatar
  • 12.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
  • 95.2k
16 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
  • 11.4k
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.6k
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,343
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
  • 44.3k
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.6k
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
  • 282
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.6k
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
  • 44.3k
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
  • 917
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
  • 66.4k
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
  • 11.4k
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
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,498
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 ...
Martin York's user avatar
  • 95.2k
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, ...
RootTwo's user avatar
  • 10k
9 votes

Merge Sort implemented using iterators

Well, interesting. There's a bug in merge_sort(): Subtracting 1 from end, without knowing ...
Deduplicator's user avatar
  • 19.3k
9 votes

Count all vowels in string

Sᴀᴍ Onᴇᴌᴀ answer has the right idea for small strings, but can be improved by using a Set to hold the vowels rather than an array. This reduces the overhead of ...
Blindman67's user avatar
  • 22.1k
9 votes

Iterator for traversing a tree [v2]

Martin York already has a very good point about the iterator, so I'll not comment on that. Avoid writing types twice In main.cpp you are writing statements like: ...
G. Sliepen's user avatar
  • 57.5k
9 votes

Counting words from stored .md files

How to modify this code, so it doesn't use forEach? One way to achieve this is using Array.prototype.reduce(): ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
9 votes

Left Shift/ Right Shift an array in C

You know, C and C++ are different languages. You used both tags, and your code is confused as to which it wants to be. It appears to use C syntax, library calls, and ways of doing things; but it ...
JDługosz's user avatar
  • 11.4k
8 votes
Accepted

QuickSort C++ Implementation using Iterators

Templates Sorting is pretty much the same regardless of the type of items being sorted, as long as you can compare and swap those things. Might as well implement the sorting and partitioning as ...
Jerry Coffin's user avatar
  • 33.6k

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