Комментарии:
Hello, I was trying to find your old video about autoresponder for Instagram in Python, but it is deleted. Could you please send me this video(if it is possible). tysm
ОтветитьI don’t think I like type hints on assignment.
Ответитьi think many people get confused by list.reverse into thinking there is one for string too
ОтветитьRecently saw a presentation on distributed computing in python using 'ray'. Thought you might like to know.
Ответитьyou can change size without changing data
from sys import getsizeof
tablica = [i+1 for i in range(1_000_000)]
print(f"Rozmiar pliku wynosi: {getsizeof(tablica)} bajtów.")
tablica = list(reversed(list(reversed(tablica))))
print(f"Rozmiar pliku wynosi: {getsizeof(tablica)} bajtów.")
Got it, I knew 'reversed()' returns reversed object, but didn't knew it was memory efficient and exhaustive.
ОтветитьThis is a great lesson on the utility of iterators as well! Makes things a lot clearer
ОтветитьWith only 48 bytes, it must keep a pointer to the original list. This would mean if the list changes a value before you grab it from the iterator, you would get the new changed value. However with strings, since they are immutable, changing the original string means secretly increasing memory usage since the iterator would keep a reference to the original string so it can't be garbage collected. So both the changed and original would reside in memory. I haven't tested this so someone can correct me if I'm wrong, but this seems like the only way this would work with so little memory consumed for the reversed object.
ОтветитьI noticed that you typed the letter 'ç', could you possibly be Turkish? 🤔 😁
ОтветитьSame as sorted, generators are nice thing
ОтветитьYou can test it out with:
numbers: list[int] = list(range(1_000_000))
(8000056 bytes)
reversed(numbers)
(48 bytes)
Pretty neat huh?