What is the meaning of list[:] in this code? [duplicate]

This is one of the gotchas! of python, that can escape beginners. The words[:] is the magic sauce here. Observe: >>> words = [‘cat’, ‘window’, ‘defenestrate’] >>> words2 = words[:] >>> words2.insert(0, ‘hello’) >>> words2 [‘hello’, ‘cat’, ‘window’, ‘defenestrate’] >>> words [‘cat’, ‘window’, ‘defenestrate’] And now without the [:]: >>> words = [‘cat’, ‘window’, ‘defenestrate’] … Read more

Parallel Loops in C++

With the parallel algorithms in C++17 we can now use: std::vector<std::string> foo; std::for_each( std::execution::par, foo.begin(), foo.end(), [](auto&& item) { //do stuff with item }); to compute loops in parallel. The first parameter specifies the execution policy

Check presence of vowels in a string

vowels = {“a”, “e”, “i”, “o”, “u”, “A”, “E”, “I”, “O”, “U”} if any(char in vowels for char in word): … Note: This is better because it short circuits, as soon as it finds the vowel in the word. So, it doesn’t have to check all the characters unless there are no vowels in the … Read more