[edit: proper place https://news.ycombinator.com/item?id=7564988]
Unpythonic Python
141–150 of 156 posts
Re: Unpythonic Python
#142Playing code golf with Python, this is the shortest I could get: https://gist.github.com/tghw/3702360 Definitely a little unpythonic.
Re: Unpythonic Python
#143Earlier quoted context omitted.
By that logic, no one should write anything in idiomatic French because anyone who isn't fluent in French wouldn't be able to read it.
I was curious about that. Is multiplying a string by a boolean idiomatic Python? I don't write nearly enough Python to know, but it strikes me that this might be more like writing French using lots of obscure words.
Treating a boolean as an integer is iffy
Multiplying a string by a boolean frankly should be a no-no.
Re: Unpythonic Python
#144 def fbg(s,r):print("\n".join(map(lambda x:str(x[1])if x[0]==''else x[0],zip(("".join(a for a,b in s if n%b==0)for n in range(1,r+1)),range(1,r+1)))))
fbg((('Fizz',3),('Buzz',5)),100)
Cause, you know, fizzbuzz one-liners need to work for the generic case.Re: Unpythonic Python
#145#include #include #include #include #include #include static char c[9]; int p(int i) { putchar(c[i++]); putchar(c[i++]); putchar(c[i+(7-i)]); putchar(c[i+(8-i)]); return 0; } int f(int i, int x) { i -= x; if(!i) { return p(x); } if(i
This'd be more fun if it didn't segfault printf(n%15 ? n%3 ? n%5 ? "%d\n" : "Buzz\n" : "Fizz\n" : "FizzBuzz\n", n);
Re: Unpythonic Python
#146Earlier quoted context omitted.
I generally don't particularly like giving punctuation meaning that, well, isn't punctuating. The bottleneck when writing code is almost never keypresses. I think CoffeeScript gets it probably the most right of languages I've worked with, in that the choice of punctuation makes intuitive sense... "Hey! It's an Arrow. It goes from here to here". FWIW, I don't like the word "lambda" either... Naming things with one let…
I cannot agree enough. Someone give me a call when a Haskell-like language with readable syntax appears. I really like the ideas behind Haskell, but the syntax is so unfriendly that I cannot be bothered to really start using it. Less special characters, please.
I suppose these things are a matter of taste as much as anything else. But when people talk about a Haskell program being 'elegant', I never think to myself "what, that mess?"
Re: Unpythonic Python
#147My for-real-not-humor implementation: def fizzbuzz(i, n): while i
Re: Unpythonic Python
#148Re: Unpythonic Python
#149When you write too much Haskell, your Python code starts to look like this: print('\n'.join( 'FizzBuzz' if x%5==0 and x%3==0 else 'Fizz' if x%3==0 else 'Buzz' if x%5==0 else str(x) for x in range(1, 101))) I would really like to have a "let" expression in Python to avoid having to write a new function with a def statement when you could get away with a simple lambda or generator expression.
Julia: print([(x%3==0) && (x%5==0) ? "FizzBuzz" : (x%3==0) ? "Fizz" : (x%5==0) ? "Buzz" : x for x in 1:100])
Re: Unpythonic Python
#150There's something minor that's always bothered me about the usual description of FizzBuzz: > If the number is divisible by 3, print Fizz instead of the number. If it’s divisible by 5, print Buzz. If it’s divisible by both 3 and 5, print FizzBuzz. In a strict interpretation, the first two sentences could be seen as incorrect. If a number is divisible by 3, you cannot just print 'Fizz' and move on. You also have to che…
This is why the description is good. Sure, it tests whether you can write a set of statements a computer can understand. But it also tests whether you can understand the intent behind a set of statements a human would make, without going on a diatribe about how the definition is not good enough. After all, if English was a formal strict language where only one right way existed to express something, we wouldn't need…
> After all, if English was a formal strict language where only one right way existed to express something, we wouldn't need programmers, would we?
This is very off-topic, but I'm not sure I agree with it. You're assuming that it would be easy to find the one unique way to express a given computation such that anybody could write it down. Even if English had this uniqueness property, I don't think that would be true at all.