Ad
  • Default User Avatar

    Nah, push() becomes redundant when class changed. Also, instructions ask to try to use push() in build_one_two_three(), so directions not really followed.

  • Custom User Avatar

    Then I stand corrected, thank you.
    I still don't like that it puts the condition after the if_true code

  • Custom User Avatar

    Ternary operator in Python is less "functional", not less "powerfull".

    Yes, you can't do such stuff with ternary, but you can call functions using ternary as well.

  • Custom User Avatar

    I should have explained myself better:
    It doesn't use the classic condition ? if_true : if_false format but the A = X if true else Y which I find less explicit and much less powerful as it's only useful for value assignment, you can't for instance do condition ? x += 1 : callFoo()

  • Custom User Avatar

    too bad python doesn't have a true ternary operator

    What?

  • Default User Avatar

    @monobrawl
    Is value if value >= last else -value a "false" ternary?

  • Custom User Avatar

    I personally considered it but opted out as I find it less readable, too bad python doesn't have a true ternary operator i.e:
    total += (value >= last ? value : -value)

    ...wait I thought it said 2 weeks not 2 years, sorry :)

  • Custom User Avatar

    It creates a new head for the given linked list or creates a new list itself, what's wrong? Seems to be correct and neat for me.

  • Custom User Avatar

    Since min_max isn't documented, you expect the argument lst to hold the following property:

    old_list = list(lst)
    min_max(lst)
    old_list == lst # element wise equal with same order
    

    After all, min_max extracts information from lst, so it's not necessary to modify the list. Changing the list would surprise the user.

    That being said, your solution runs in O(n log n) compared to the optimal O(n). If you don't know the O-notation: if the list has n elements, your solution needs about s * (n * log n) operations to get the minimum (where s is some constant), whereas an optimal solution only uses s' * n operations (where s' is another constant). If you're interested in O-notation, search for "Big O notation" or "Landau notation".

  • Custom User Avatar

    And why is it dangerous? Do you think I could lost some part of imput or is it a question of Best Practices?
    I'm not really experienced programmer so thank you in advance for your answer.