Ad
  • Custom User Avatar

    Pro dev here, avoid doing this in production/interviews would be my suggestion. It just makes things more confusing for any other devs your working with, and even your reviewers looking over your PR. Generally the shortest solution for every python problem here is an example of what not to do in production or for interviews.
    That being said, I like doing things like this in my personal code.

  • Custom User Avatar

    True or False obviously. But in Python True also equals 1, and False equals 0.

  • Default User Avatar
  • Custom User Avatar

    This solution is not intended for production or readability (although I find it readable okay). I was just having fun and exploring how to write down logic with minimal overhead symbols and concepts. Consider tuple a way to substitute a switch statement.
    P.S. I am not a professional dev either.

  • Default User Avatar

    professional dev either, but in my opinion, "clever code", "tricky" or "tricky to understand at first glance" would not be of value to large teams (in a serious manner), if people would spend the time they could be actually working trying to understand something someone else has done in order to use it, or modify it (maybe?), it won't be so productive. It is really cool to see someone knowledgeable enough to write code like this, it shows that he knows the language well, and can do things not so many people would try to do, it's tricky, elegant, and very clever as many people wrote here, no doubt about it! But if you're in a team, you have deadlines, basically, you're trying to spend more time coding rather than staring at someone else's code thinking "how does this even work" or something similar, basically it's hurting the workflow instead of making it easier for the team to understand it right away and come up with things faster. To make a comparison, imagine you have to use math to do something, in math, you can do things in many ways and get the same outcome, but sometimes you can use formulas to make more extended calculations take less time, in this case, "the formula" would be making the code easier to read, so that anyone that knows the language enough (not necessarily THAT much) can spend little time trying to understand it, and more time being productive. Clever or tricky code is like having a math problem solved with many calculations instead of using any formulas to make it shorter and easier to understand. I don't really know if that analogy is understandable enough to address the situation, but I tried to explain my point, lol.
    There are instances where clever code is used to make the program more efficient (using Big O notation to calculate the algorithm's efficiency/complexity), 100%, but I'd stick with "easier to understand" over "clever/tricky" if maximum efficiency wasn't a goal, or if it didn't really have an advantage compared to simpler code.
    English is not my first language, sorry if I didn't write everything correctly.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    It updates all alive cells for the current iteration, putting them in a set based the previous iteration.

  • Custom User Avatar

    maybe not the sexiest solution out here but by far most readable and easy to trace. thanks!

  • Custom User Avatar

    this looks very cool and the solution is probably great - except I can't understand what "cells = " expressions do... Some comments for newbies like me would be super helpful.
    I'm also wondering whether an experienced python dev can easily understand such expressions written by somebody without comments? Just curious.

  • Custom User Avatar

    absolutely amazing and elegant. I'm not a professional dev - I'm wondering if people indeed use such code in large/enterprise teams or go with simple/easier to read lines?

  • Custom User Avatar

    Figuring out how to sort (char_count desc then substring asc) took me 80% of total time spent (python)...
    What if I needed to sort (text_field_1 asc then text_field_2 desc) - how would I do it in Python?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    you need to think of a different algo/solution that doesn't use four loops

    any more hints and i'll have to give away the answer ;)

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution