Ad
  • Custom User Avatar

    The if/elsif/else can be condensed down to simply:

    total += dict[c] if dict[c] >= last else -dict[c]

    To start the loop you know dict[c] can't be less than last. This removes the redundant code.

  • Default User Avatar

    This doesn't really solve the Kata according to the instructions. What is the point of the push function in your implementation?

  • Default User Avatar

    As bkaes said, you don't want to surprise the user by modifying the input list. Lists and dictionaries are examples of data types that are mutable, so when you change an input list in the local function space, you are also changing the input list in the caller space. This can be a useful feature of these data types, but requires special care sometimes.

    Additionally, you could have just returned [lst[0], lst[-1]] instead of creating the tempor variable.

  • Default User Avatar

    A bit dangerous because you have modified the input list using the .sort() method. Sorting a copy or creating a new list using sorted avoids this situation.