11
Bogusław Kałka
Last seen 5 years ago
Member for 9 years, 8 months, 9 days
Difficulty Normal
Some optimization could be done: check if newly found palindrom (lines 6-7) is longer than longest already found, so you have to remember only one string, instead of list of strings.
More
You can just compare lists returned by sorted - no need to ''.join() again for strings.
Also after replace(' ', '') there is no need for strip() because there won't be any spaces to strip.
More
This is memory-cpu dillema task. In above code year is calculated every time function is called: uses little memory, much more cpu. Another way is to calculate every year-opacity pair only once at beginning and save it to list. Uses more memory, but less cpu. As you did for "fibs" list - it is compu
More
Creative use of replace :) (of course there is str.endswith() which would be more apropriate in this task).
More
Could be faster if lists where used instead of sets - no need to secondary check for characters count then.
More
You can write first_word.lower().replace() instead of (first_word.lower()).replace() - chaining of functions.
Also "return a == b" is equivalent to, and easier to use, than "return (True if a == b else False)".
More
Good idea with calculating ang_c from two previously calculated angs.
Are you sure that try/except will catch every non-triangle data with ValueError and ang_a==0 checks?
More