# Tag Info

Accepted

### Counting all the vowels in a passage of text

Change to lower once: text.lower() instead of t.lower() inside loop. Use t in vowels to ...
• 703
Accepted

### Incrementing Integers in Map

You have several different options for this: Guava Google's Guava Library introduces the idea of a Multiset which is capable of counting the occurrences, and also provides a couple of other features....
• 58.3k
Accepted

### Codewars: Reduce strings to one character

First I would choose a different representation of the colors during the computation, to avoid the “expensive” COLORS-{a, b}).pop() operation, which is executed ...
• 22.6k
Accepted

### Adjacency List Graph representation on python

Here are two ways you could represent a graph with weighted edges in Python: Represent a graph as a mapping from a node $n$ to a mapping from neighbouring node $m$ to the weight $w$ of the edge ...
• 49.3k
Accepted

### Extraction of value from a dict-tree, given a path of arbitrary length

Recursive Approach Review In this method you are performing too many look-ups. First, you are looking up the 0th value of p two or three times. List indexing ...
• 32.2k
Accepted

### The cleanest way to print the max value and its key from a dictionary

What would you do differently from this? PEP 8: Variable names should be lowercase. People -> people. As @FMc suggested in ...
• 5,487
Accepted

### Efficient renaming of dict keys from another dict's values - Python

I'd use a dict comprehension: pretty_dict = {replacement_keys[k]: v for k, v in ugly_dict.items()} This throws an error if ...
• 2,983
Accepted

### Merging two dictionaries together whilst adding keys but multiplying values

It's standard to indent Python with 4 spaces. Not following this standard only makes your life and the life of people that have to interact with you harder. You can just use the optional default ...
• 41.7k

### HashTable implementation

Implementing a hash table This hash table implementation is a bit limited: it supports only String keys and int values. It would be good to generalize it. When ...
• 110k
Accepted

### Count the occurrence of each unique word in the file

Efficiency I won't say much about efficiency - because without a clear use-case it will be hard to know whether possible changes would be worth the effort - but my main concern would be fact that you ...
• 7,116
Accepted

### Check for null/empty in dictionary

Each of these: ...
• 10.9k
Accepted

### List all possible permutations from a python dictionary of lists

The tool you need here is itertools.product: ...
• 49.3k

### DuplicateDictionary - A dictionary-like class which allows duplicates

Such a data structure already exists, and is called ILookup<TKey, TElement>. It can be created using the ToLookup ...
• 1,167
Accepted

### Dictionary GetValueOrDefault

I'm pretty sure there's no better way to do this but I thought a consensus on here might be nice. Let me know what you think. At first glance it seems to be ok but one could assume that he/she is ...
• 50k
Accepted

### Sorting dictionary alphabetically

I'm afraid your sorting is in vain because the normal dictionary does not guarantee that the items will be enumerated in the same order as you added them: For purposes of enumeration, each item in ...
• 43.9k

### Removing entries from a dictionary containing bad words

The current time complexity is $O(N * M)$ where $N$ is the number of quotes and $M$ is the number of bad words. For every single word in a quote you are iterating over all the bad words to check ...
• 17.1k

### Determine if one string is a permutation of the another

I would say yes, use an array. Arrays afford very good memory locality, which is good for cache performance. They essentially are the most basic and efficient hash map if the key is the index. You ...
• 5,751
Accepted

• 92.1k
Accepted

### Implementing a rectangle class

PEP-8 Class names should be CapWords, so instead of rectangle you should have Rectangle. ...
• 32.2k
Accepted

### Convert a list of dictionaries to a dictionary of dictionaries

While using methods with side effects in list- or dict-comprehensions is generally frowned upon, in this case you could make use of dict.pop to get the ...
• 1,704

### HashTable implementation in C++

First and foremost there is std::unordered_map. If you just need a hash map, use it. What's wrong Your hash is an int, if your string consists of negative chars ...
• 762
Accepted

### Adding to a dictionary and skipping duplicate keys

Generating and handling exceptions is considered to be an expensive operation, so if(! x.ContainsKey()) is better. Yeah, the code example I see in MSDN uses try/...
• 6,625
Accepted

### Simple C# HashTable Implementation

A few small points: public class HashTable<T, TU> Use more mnemonic names, like TKey, TValue here. ...
• 14.6k
Accepted

### Extending CGPoint to conform to Hashable

I can see no advantage of computing the hash value from Int(self.x) and Int(self.y). As you already noticed, truncating the ...
• 22.6k
Accepted

### Brick Wall Leetcode challenge

You could look at it in a different way, transform the wall of bricks to a wall of edges, in your example it would be 1, 3, 5 3, 4 1, 4 2 3, 4 1, 4, 5 The first, ...
• 395

### Removing entries from a dictionary containing bad words

This code is incorrect: re.compile(r'\b({0})\b'.format(w), flags=re.IGNORECASE) If w contains any metacharacters, then this ...
• 1,169
Accepted

### Invert a dictionary to a dictionary of lists

You are right, you should not use a list comprehension just for its side-effects. It is not very readable and only confuses the reader of the code. Instead, just make it ...
• 40.6k
Accepted

### Determine if one string is a permutation of the another

Comparing two maps is linear, so that's not a big problem. I don't think you've made particularly good use of maps though. As I see it, you have two choices. You could use an ...
• 33.2k
Accepted

### Hashtable Implementation - C

I spotted some bugs: The functions malloc and realloc might fail if there is not enough memory, and in this case they would ...
• 49.3k