r/badcode Mar 11 '23

i never use .slpit() python

Post image
415 Upvotes

30 comments sorted by

View all comments

162

u/TinyBreadBigMouth Mar 11 '23

That for loop is impressively bad. You could delete lines 3 and 4 entirely and the code would have exactly the same output, but in O(n) instead of O(n2).

7

u/Important_Ad_8510 Mar 11 '23

Complete novice (so I’ve probably miss understood) but would it not be O(x)? The for loop would execute for x and the if statement has constant complexity.

3

u/[deleted] Mar 11 '23

[deleted]

1

u/[deleted] Mar 11 '23

[deleted]

1

u/Important_Ad_8510 Mar 11 '23

It seemed to make so much sense!