11
Last seen 3 years ago
Member for 9 years, 1 month, 17 days
Difficulty Normal
How do you not get headaches when writing something like this? I get them just from _reading_ it. ;)
More
\D
> [Matches any character which is not a Unicode decimal digit.](https://docs.python.org/3/library/re.html)
Not exactly what was asked for. Only the precondition saves you from unwanted results. :)
More
If I have to scroll horizontally to read it, it is not clear. -1 for bad style.
The approach I like. I used the same.
More
Not very speedy. You are iterating over the whole text, which by definition must be at least as long as the alphabet you are checking against. Iterating over the alphabet is the faster solution. And, of course return false immediatly, if text isn't even long enough. ;)
Also, you are checking all le
More
I was thinking about using a dictionary, but being fairly new to the concept, I couldn't figure it out. Thanks for this great solution.
More
Your RE is a bit repetitious.
if re.search(r'([a-z]+\s){2}[a-z]+', words, re.IGNORECASE):
is shorter and somewhat clearer in my opinion.
Anyway, I don't like throwing REs at everything, when there are simpler means available. **str.isalpha()** is a built-in method, so no need to **import re**.
More
Nice approach. But it took me a while to grasp what's happening. I'd say that makes it a little less clear. ;)
Oh, and line 19 should be the other way around:
if state[0] != '.' and len(set(state)) == 1: # no point for set() if [0] is '.'
But that's just a minor thing.
More
Lol, I also had the idea to use a dictionary and enumeration. But somehow it didn't cross my mind to just use enumerate directly, so I put it in a dict comprehension. Silly me. ;)
Oh, the use of recursion is nice too. At one point I thought about it and then dismissed it after failing to find the r
More
Could have just used the built-in abs() instead of importing fabs from math. ;)
More
Oh dear! There is not a single iteration in there. I hope your fingers hurt after typing that. ;)
More
I don't think, this is particularly speedy. **text.lower()** is called for every letter in the alphabet. Once, outside the loop, would have sufficed.
More
I like the **union** idea. But your list is waste of space, when there are duplicate connections in the initialization, like {"a", "b"} and {"b", "a"}. You could have made that list into a **set** of **frozensets**.
Reusing the names() method is nice, though. I had forgotten to think about that. ;)
More
Line 6: __range(len(names_of_rel))__ would be more flexible, in case someone decided to put multi-level connections in __network__. ;)
Lines 7 through 11: You use __names_of_rel[i]__ _four times_ and __names_of_rel[1-i]__ twice. Those are list operations, which cost time, but the values don't chang
More
You could do
if digit:
result *= digit
one lines 9 and 10; more concise that way. Do away with line 5 and instead on line 7
for str_digit in str(number)
no point in creating a variable if it's only used once. ;)
More
The int conversion is not necessary, because bools are also ints. Also, you could have broken up line 1 into multiple lines. This is not very readable.
More
I like the len(args) < 2, hadn't thought about that. The print statements are unnecessary, though.
I also think iterating over args twice is a bit much. If a is not greater than max, check if it is smaller than min in the same iteration. Shouldn't make it any less clear.
More
Clever trick with the [o[:2]] there. ;)
But this also has to create all the dictionary elements, and for that, all the boolean operation for the values need to be performed.
More
Doesn't look very speedy to me. You do nothing with **OPERATION_NAMES**, so why create it? That's wasted CPU time right there. ;)
Also the int() conversions are unnecessary, because *bool* is a subclass of **int**.
More