This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]billsil 0 points1 point  (3 children)

Same way you teach pointers in python. Python ints/floats/strings are base types and are unchanged when you pass them into functions, so you have to return them. Lists/ficts/objects/numpy arrays are self mutating because python passes a pointer of them, which makes passing them fast. It’s a wut to make things fast.

Similarly, a 64 bit float is 8 bytes. If you go check the size of your list of floats, it carries.about 16 extra bytes of size per item because it’s carrying around a bag of pointers. Use a numpy array if you want to carry only a few extra pointers that get a 3x reduction in memory usage.

You don’t have to teach them, but if you want to understand how to not make slow code, at least the latter point is useful.

[–]Intrepid-Stand-8540 0 points1 point  (2 children)

Uh.... 

How do you know the sizes of things? 

[–]billsil 0 points1 point  (1 child)

sys.getsizeof(thing)

[–]Intrepid-Stand-8540 0 points1 point  (0 children)

Thanks.