News for hackers. Stuff that matters.
Re:Minimal examples of data structures and algorithms in Python by santiagobasulto on Monday April 24, 2017 @06:34PM (#14189045)
With all due respect, these might be good examples for people trying to learn algorithms and data structures, but it's not a good example of Pythonic code. Here's an example of one of the group projects in our course, that implements a "Pythonic" Linked List, relying on Iterators and Magic methods: https://github.com/rmotr-group-projects/pyp-w2-gw-linked-lis...

(switch to the branch master if you don't want to see the solution and want to give it a try by yourself).

In any case, if OP is the owner of the repo, good job compiling all that code together.

Re:Minimal examples of data structures and algorithms in Python by zimablue on Tuesday April 25, 2017 @04:45AM (#14191785)
As someone who's written in a few languages and is now learning/writing Python full time, "pythonic" is starting to cause me a twitch of pain every time I read it.

It seems to imply the Python has the final solution in how to write code and therefore everything should be written in the way that Python elders have decided.

Main example: I don't really like list comprehensions. They're pretty much the same thing as map/filter but less understandable or composable, nevermind you fix (with your choice of brackets in multiple places) your choice of list vs generator vs "pushing source" (not sure the right word) which you wouldn't have to with transducers.

http://stackoverflow.com/questions/952914/making-a-flat-list...

I'd rather read code where someone wrote "flatten".

Re:Minimal examples of data structures and algorithms in Python by terminalcommand on Tuesday April 25, 2017 @10:35AM (#14193863)
IMHO pythonic means that you adhere with the principle "there should be one --and preferably only one -- obvious way to do it". And that one way is set out by the BDFL Guido :).

I have theory that, python was introduced out of frustration with Perl. As we all know, Perl had the principle of TIMTOWTDI.

Another far more tangential and biased theory here: As Python imposes strict programming principles, it resembles Java in forcing the programmer to abide by the styles set out by the language designers. And maybe that's why schools prefer to teach Python instead of Ruby as a scripting language.

PS: I have nothing against Java and I love Python. My theory is based upon Guido's insistence on not opening the language fully to functional programming. I'd like to see better lambdas, functional programming without itertools etc. But I know Guido has his reasons, pythonic code uses list comprehensions instead of FP.

Re:Minimal examples of data structures and algorithms in Python by dahart on Monday April 24, 2017 @07:52PM (#14189568)
So, the title does say these are examples of structure & algorithms, and doesn't claim to be "pythonic". But why do you feel like using iterators makes it more "pythonic" than not using iterators? Is your list implementation more concise or better expressed? Does it handle cases the article doesn't?

The code in the repo looks pythonic to me. This one looks pythonic to me. http://stackoverflow.com/a/283630/1424242

Re:Minimal examples of data structures and algorithms in Python by pryelluw on Monday April 24, 2017 @07:06PM (#14189259)
Stupid question:

Interface.py follows a pattern Ive seen in Java but not in Python. Am I simply too much of a Python noob?

Re:Minimal examples of data structures and algorithms in Python by orf on Monday April 24, 2017 @07:14PM (#14189311)
No, it's not a particularly pythonic thing to do, but it's not uncommon to have a bass class with some methods that should be implemented by children and throw an exception if not. That's not quite an interface as Java has it though.
Re:Minimal examples of data structures and algorithms in Python by pryelluw on Tuesday April 25, 2017 @12:48AM (#14190852)
Ok, that's what I thought. Thanks for the reply.