Ad
  • Custom User Avatar

    Python noob here, I gotta say Python one-liners like list comprehension are starting to look pretty understandable (at this level of complexity, at least...)
    But cramming logic that repeats on each 'x' doesn't look good for Big O, for sure.

  • Custom User Avatar

    You are absolutely right! However, in codewars I view 1-line solutions more like a mini-achievement of making a code in one line, rather than the practical solution and I think there can't be good argument against writing your code in a more coherent way, naming almost every variable in an understandable way so others didn't have the hard time reading your code

  • Default User Avatar

    Nitpicks: 1. you could use list comprehension which I believe is not necessarily unreadable (i.e. it doesn't violate "just because you can doesn't mean you should") 2. no need to calculate len(string) every time.

    But overall, +100 for "just becuase you can doesn't mean you should". Production code is generally not a place for showing off, it's also a tool to communicate with other people.

  • Default User Avatar

    You can have 10 computational operations in 1 line or 10 lines, it's still 10 operations for the compiler and the transistors. Fewer lines ≠ better efficiency.

    Industry standard is generally "good code is code that your mom can read and get an idea how it works without squinting too hard." Code really is for humans to read, even if there were tiny inefficiencies in one implementation over another, it's usually still best to go for the implementation people will have an easier time understanding. That's why recursion is rarely accepted in real-world code reviews: it usually makes more sense as a loop.

  • Default User Avatar

    Isn't it for efficency? I assume that in a large project with mutiple one liners helps reduce the runtime of the program significantly and speed is key in any project. and its not like this is a very advance code, its very logical. I dont know the industry standard but this just my thoughts from a aspiring data scientist

  • Custom User Avatar

    This solution is more concise and efficient, while at the same time still very readable.

  • Custom User Avatar

    yeah i dont know if it sends the right message for beginners.

  • Custom User Avatar

    Thanks. Exactly my thoughts when I started learning doing these unreadable one-liners. Is it cool to utilize the features of Python to achieve this? Yes. Would I do it in my professional work? Hell no.

    On the other hand, should I code in the C-like program structure? This is a lot one tends to do when coming from C/C++ background, but that would be a great underutilization of Python features, so why work with Python in the first place...

    As with many things in life - the truth lies somewhere in between. :)

  • Default User Avatar

    I never thought about it this way before. Thank you, your text was an eye opener for a beginner like me.

  • Default User Avatar
  • Default User Avatar

    You are welcome, glad you learn something through it ;-)

  • Default User Avatar

    I wasn’t familiar with DFS algorithms, until now :) I'm fairly algo ignorant still, but a little less so because of you. Thanks for taking the time to put the logic into words so well.

  • Default User Avatar

    You were right about documentation so here is a fork of this solution, explaining it step-by-step.

  • Default User Avatar

    I noticed that! First thing I did was check this person's profile, and I was happy to see it banned. I'm glad the mods take it seriously :)

  • Custom User Avatar

    If you do this (I don't know if this cheat is still working), you will just get banned :) There are filters to detect this kind of code and the moderators are not happy with it...

  • Loading more items...