23
Alissa Kvashina
Last seen 2 years ago
Member for 10 years, 2 months, 29 days
Difficulty Normal
If all elements are the same, they should all be equal to the first one, so no need to bother with indexes. Also, take a look at ```all()``` function.
More
There is ```str.find(text)``` function that returns -1 if the ```text``` is not found. You could precalculate indexes of begin and end and work with those. It would be much faster (not that you really care, as these are just exercises). It would also allow you to use things like ```max(begin, 0)```
More
You know you can treat string as a list of chars, right? You could filter it and then join back. Also, no need for if at the end, just return result of comparison.
More
You could use text.find(symbol, first_index+1). No need to slice beforehand if start index is an option for method. And you won't need to add first index as well.
More
I'd rather store the result of ```text.find(symbol, text.find(symbol) + 1)``` in a variable. It makes it more obvious that it's the same result.
More
You could use ```list.index(x)``` instead of copying list over and over. It would be both more readable and faster/cheaper.
More
Nice solution, but consider using a list generator instead of appending in a cycle. It's both faster and more readable.
Also, there is such a nice function as ```str.capitalize()``` try using it next time you need to make the first symbol uppercase.
More
Just an idea: if you multiply a string by 0 it becomes empty. And you can concatenate strings. So, this can be solved without any ifs.
Also, there is a str.lstrip(chars_to_strip) function, that can be helpful here.
Treating strings as arrays is often useful and always tempting, but try to think abou
More
Boolean expression becomes too long here. It's better to split it somehow. For example, you could take the last condition and put it above (`if 'password' in password.lower(): return False`).
Usually people set line length limit somewhere between 100 and 140 symbols and consider that a condition th
More
I like generators very much, but try using composition of `map()`, `filter()`, etc. It doesn't look very good in Python because of brackets nesting, but it's a good excercise.
More
Psst, want some hint?
chr(ord('e5'[0])-1) will give you 'd' and str(int('e5'[1])-1) will give you '4', so you can just check if 'd4' (sum of previous expressions) is in pawns. It's cooler than writing a dict and rewriting all input
More
This solution could become much more readable if you'd come up with more meaningful naves for your variables. Developing a habit of always making good variables' names will save you much time and pain later in your career.
More
Cool. I couldn't find way to form dict autoaticaly and didn't want to type in too much, so my solution is way more complicated. This makes me upset of being lame, but, well, I'm not a professional programmer, just learning :)
More
I like your solution, but I have two questions:
Why not i.isalpha() instead of regexp?
And what for are capital letters in regexp?
More
Nice solution, but as for me it's better to use
mid = len(data)//2
I think that it might be cheaper, and also more clear.
More