Post B6OS9ooAyh5ptvvkwK by civodul@toot.aquilenet.fr
 (DIR) More posts by civodul@toot.aquilenet.fr
 (DIR) Post #B6NqsxatMZ9pvGobSK by civodul@toot.aquilenet.fr
       1 likes, 0 repeats
       
       I was reminded that the thing called “list” in Python is actually implemented as a vector, with O(1) random access and O(n) insertion:https://wiki.python.org/moin/TimeComplexityAs a vehicle for teaching, it sounds terrible.
       
 (DIR) Post #B6OS9oZzpPkbBxIQq0 by csepp@merveilles.town
       0 likes, 0 repeats
       
       @civodul Why would that make it bad for teaching?You rarely need to insert an element in a random place, and if you only grow the list at the end and if alloc speed/size is becoming an issue, 90% of the time you can drop the braces from the list comprehension and work directly on generators instead, which usually gives you O(1) memory use.And idiomatic Python uses iterators in loops, so you can actually use whatever underlying data structure you want, as long as it supports __iter__, or indexing for when you want random access.This is *much* better than assuming everything is a linked list.  (Source: I've tried to use generators in Guile.  It was pain, nothing was prepared to take or produce them.)
       
 (DIR) Post #B6OS9ooAyh5ptvvkwK by civodul@toot.aquilenet.fr
       0 likes, 0 repeats
       
       @csepp It’s at least a problem to call it “list”: if you’re going to teach complexity, calling vectors “lists” is just adding confusion.
       
 (DIR) Post #B6P6jYBEH69IvBJ488 by sharlatan@mastodon.social
       0 likes, 0 repeats
       
       @civodul I recently found out that 0.1 == 0.1False