“Список кортежей против” Ответ

Список против корпуса

# compare the size
import sys
my_list = [0, 1, 2, "hello", True]
my_tuple = (0, 1, 2, "hello", True)
print(sys.getsizeof(my_list), "bytes")
print(sys.getsizeof(my_tuple), "bytes")

# compare the execution time of a list vs. tuple creation statement
import timeit
print(timeit.timeit(stmt="[0, 1, 2, 3, 4, 5]", number=1000000))
print(timeit.timeit(stmt="(0, 1, 2, 3, 4, 5)", number=1000000))
Tough Tarsier

Список кортежей против

# A tuple might contain data about a person (heterogeneous type mixture)
person_a = (name, age, occupation, address)

# A list might contain a list of people (homogeneous type mixture - all tuples!)
people = [person_a, person_b, person_c]
Drab Dolphin

Ответы похожие на “Список кортежей против”

Вопросы похожие на “Список кортежей против”

Больше похожих ответов на “Список кортежей против” по Python

Смотреть популярные ответы по языку

Смотреть другие языки программирования