9 points

you can even have a case where you return the first element of the list if the list is not empty, and it will still be O(1).

permalink
report
reply
12 points

you can make it sort the first k elements and it will still be O(1). Set k high enough and it might even be useful

permalink
report
parent
reply
1 point

By that logic, any sorting implementation is O(1), as the indexing variable/address type has limited size

permalink
report
parent
reply
5 points

I set k to 50,000,000,000… that’s more items than my shitty computer can fit in memory (including swsp) but I am now happy to celebrate my O(1) algorithm.

permalink
report
parent
reply
21 points

Besides the obvious flaws… is that parameter a list named list, shadowing the list() constructor?

permalink
report
reply
-2 points

That is a type hint

permalink
report
parent
reply

Well duh. I wonder what happens if you shadow the list constructor and try to use it as a type hint…

def foo(list: list):
  def bar(thingies: list):
    pass
permalink
report
parent
reply
5 points

It works as long as you don’t call list() within that function.

permalink
report
parent
reply
27 points

inplace sort be like:

def sort(list: list):
    list.clear()
permalink
report
reply
36 points

Lossy sort

permalink
report
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 7.7K

    Monthly active users

  • 977

    Posts

  • 38K

    Comments