57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 23 hours ago
Member for 11 years, 6 months, 7 days
Difficulty Advanced
We shall not cease from exploration, and the end of all our exploring will be to arrive where we started and know the place for the first time.
Since you have two lines anyway, how about extracting definition of l to separate line? :-)
Also, you shouldn't use mutable defaults unless you _really_ know what you're doing. ps=() is much better. (Usually, = in default definitions doesn't have spaces around it. At least PEP8 says so.:)
More
Yes, that's how a 7bit washing machine embedded microprocessor would solve the problem. :-D Python has a bit richer data structures on your disposal. :-]
(Unfortunately, the code for 8 is not valid ASCII... but neither is its complement. Ah, the good old times of punched cards...:)
More
What's bad and what's surprise here? (except CiO Python finally supports yield from:).
I consider isinstance(x, list) a bit nicer than type(x) == list. And it will work for subclasses of list too. ;-)
More
Here is your code, halved:
import itertools, operator
def trim(lists):
if lists:
first, *rest = lists
for t in [first] + [first[::-1]]*(first[0]!=first[1]):
for remains in trim(rest): yield [t] + remains
else: yield []
def sqgen
More
Nice twist. You could have gotten away with slicing (or re.sub), instead of that boring replace. ;-)
More
That's an ok solution. However, it would be much nicer (faster, shorter, less memory, more readable, more Pythonic) to use generator expression instead of list comprehension. Just drop the brackets []. ;-)
More
Line 7 can be written: if num in cur_alpha.
Or better yet, use EAFP instead of twice going through. Just remove lines 6~8, change .find to .index in line 10, catch ValueError and return -1 in that case.
More
Those Lego bricks really fit into one another. :-D
More
You can use sum builtin instead of manual management of count, and you can use enumerate instead of manual index management. ;-)
More
... but def loop. :-)
Nice. Though you didn't really need another function... checkio could be called recursively. :^)
More
If you're importing itertools, cycle would be much better fit than count.
More
Nice check whether xor has <=1 set bit. :-) But...
* range(0, len(image), 4) would probably be clearer. Or alternatively, at least use my "slice twice" technique: image[i\*4:i\*4+4] -> image[i\*4:][:4].
* x * (1 << j) is simply x << j.
More
Line 9 is really head-scratching. :-)
begin += -y if y in fib else 1
might be a better way. Also, that alignment is not Pythonic.
And that hardcoded fibonaccies are ugly. Much better is to write a generator.
More
Line 27 can be
del braille_out[-1]
Also in line 19, you should learn about str.ljust method. It's useful. ;-)
In line 10 you don't need a dict: .update(zip(... is ok.
Height and width of a Braille character are not likely to change. You seem to me like person defining
M = 12 # number o
More
Don't you think this code duplication is horrible? :-P And even that's inconsistent, since units are handled differently than tens and hundreds.
Why tab (== lookup) as a separate argument? It's not that it ever changes. Just use that local variable.
Why str(tab[...]) instead of just tab[...]?
str
More
A few stylistic remarks, and a big problem:
* a-b>0 is much clearer written as a>b (you use it 5 times, and inconsistently)
* [building[0],building[2],building[4]] can be written as a slice: building[::2]
* you can just say: numberBuildings+=visible at the end, bools know how to count.
* The
More