3 ms·
Then why isn’t there a function to flatten a list in Python? I’m not sure what Python’s priorities are, besides majorly sucking. I can write software in Scala
by mruts 7y ago
Then why isn’t there a function to flatten a list in Python?
I’m not sure what Python’s priorities are, besides majorly sucking.
I can write software in Scala or OCaml or Racket in less than half the time of Python, while also being 10x faster.
Python needs to die. It’s the most worthless language I’ve ever been forced to use.
- dikei 7y agoFlatten a list in Python using list comprehension flat_list = [item for sub_list in orig_list for item in sublist ] Using itertools flat_list = list(itertools.chain.from_iterable(orig_list))
- mruts 7y agoYeah, of course you can flatten a list. It seems like Python programmers enjoy writing the same code over and over again. Would it really be bad if I could just do lst.flatten ? Or flatten(lst)?
- o_nate 7y agoThere's a case to be made that flattening a list is not a common enough operation to justify a built-in keyword or even a method on the standard library list class. The Pythonic way seems to be that if you can write something with a simple and clear one-liner then it's better and clearer to have people use that one-liner than another built-in method that people would have to go look up the implementation of.
- mruts 7y agoI mean, you don’t believe that, do you? Maybe we should all be writing our own sorting algorithms as well. I kind of assumed that DRY was a universally accepted principle in software engineering. But I guess the Pythonic way is about copy and pasted code, no abstractions, wasting people’s time, egregious language inconsistencies, no multi-threading, and terrible performance. I’ve probably written more Python than any other language, and honestly, using it feels bad. It feels outdated and useless.
- marmaduke 7y agoI think you're feeding a troll here. Anyone with time enough in engineering or programming can recognize and respect these sorts of tradeoffs without trash talking least favorite tool.
- dragonwriter 7y ago> Then why isn’t there a function to flatten a list in Python? There's a function to flatten an arbitrary iterable into a flattened iterable and a function to turn any iterable into a list. > I can write software in Scala or OCaml or Racket in less than half the time of Python, while also being 10x faster. Many people, on many types of problems, find the reverse of the first relationship.
- mruts 7y agoWhat tangible advantages does Python have compared to Racket? The only thing I can think of are the high quality data science libraries.
- marmaduke 7y ago> why isn’t there a function to flatten a list in Python? After a decade of writing and maintaining Python, I've never needed to flatten a list. > can write software in Scala I have seen projects in Scala and can't make sense of the types or data flow. When I show non Python programmers a snippet of Python they have a good chance of getting the sense of it.