Từ điển có nhanh hơn danh sách Python không?

Trong python

a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
4 là một đối tượng ánh xạ ánh xạ các giá trị
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
5 thành các đối tượng
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
6. Đó là
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
7 của python và chỉ có một loại
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
8 tiêu chuẩn là
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
4. Nó cũng là
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
2. Python
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
4 có một cặp
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
32,
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
33 trong đó
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
34 gần như tùy ý và các giá trị không phải là
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
35 như các giá trị chứa
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
3,
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
4 hoặc các loại
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
2 khác không được sử dụng làm
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
34 trong
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
4

Các loại số được sử dụng cho

a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
34 tuân theo các quy tắc thông thường cho
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
12. nếu hai số so sánh bằng nhau [chẳng hạn như
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
13 và
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
14] thì chúng có thể được sử dụng thay thế cho nhau để lập chỉ mục cho cùng một
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
15

a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
16, Từ điển có thể được tạo bằng nhiều cách khác nhau, nhưng cách đơn giản nhất để tạo từ điển là chuyển cặp
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
17 tách biệt gồm
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
34 và
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
19 bên trong một
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
90.
Các cách khác nhau để tạo từ điển.

  1. Sử dụng danh sách khóa được phân tách bằng dấu phẩy. cặp giá trị trong dấu ngoặc nhọn
  2. Sử dụng hiểu chính tả
  3. Sử dụng hàm tạo kiểu

a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]

Vào chế độ toàn màn hình Thoát chế độ toàn màn hình

Tất cả các ví dụ trên trả về một từ điển bằng

a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
91

Bây giờ, chúng ta đến với chủ đề của chúng ta. Chúng tôi thường sử dụng danh sách trong các chương trình của mình vì danh sách dễ sử dụng nhưng nếu chúng tôi có một số lượng lớn các mục, chẳng hạn như

a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
92 thì sao. Sau đó,
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
16 mất nhiều thời gian để tra cứu bất kỳ mục nào nhưng nếu chúng ta thực hiện nhiệm vụ tương tự với
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
4 thì nó được thực hiện khá nhanh, bởi vì trong Python, độ phức tạp thời gian trung bình của một
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
95 là
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
96, vì chúng được triển khai dưới dạng bảng băm. Độ phức tạp thời gian của
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
97 trung bình là
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
98. Nhưng có một vấn đề nữa khi sử dụng
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
4 là nó chiếm nhiều dung lượng khi lưu trữ cặp
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
34 và
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
19 so với
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
16. Đó là tình huống tốt nhất của
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
33

Nếu bạn tìm kiếm một số khóa cố định, nếu bạn tăng kích thước đống cỏ khô của mình [tôi. e. kích thước của bộ sưu tập mà bạn đang tìm kiếm] bởi

a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
34 từ mục nhập
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
35 đến mục nhập
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
36, sử dụng
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
37 sẽ nhanh hơn
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
38 so với sử dụng
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
3. [Nguồn. Trăn thông thạo bởi Luciano Ramalho]

Nhưng sau

a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
20, chúng tôi có một triển khai mới của
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
37, mất ít hơn
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
22 so với trước đó, vì vậy bây giờ nó không còn là một
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
33 nữa

Loại

a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
37 đã được triển khai lại để sử dụng biểu diễn nhỏ gọn hơn dựa trên đề xuất của Raymond Hettinger và tương tự như triển khai
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
25. Điều này dẫn đến việc từ điển sử dụng ít bộ nhớ hơn
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
26 so với
a = dict[one=1, two=2, three=3]
b = {'one': 1, 'two': 2, 'three': 3}
c = dict[zip[['one', 'two', 'three'], [1, 2, 3]]]
d = dict[[['two', 2], ['one', 1], ['three', 3]]]
e = dict[{'three': 3, 'one': 1, 'two': 2}]
f = dict[{'one': 1, 'three': 3}, two=2]
27. [Nguồn. con trăn. tổ chức]

Tại sao từ điển nhanh hơn danh sách?

Danh sách là một tập hợp dữ liệu được sắp xếp theo thứ tự, trong khi các từ điển lưu trữ dữ liệu dưới dạng các cặp khóa-giá trị bằng cách sử dụng cấu trúc hashtable. Do đó, việc tìm nạp các phần tử từ cấu trúc dữ liệu danh sách khá phức tạp so với từ điển trong Python . Do đó, từ điển nhanh hơn danh sách trong Python.

dict[] hay {} nhanh hơn?

Như chúng ta có thể thấy, dict[] rõ ràng là chậm hơn {} . Đặc biệt nếu dictionary được khởi tạo nhiều phần tử thì ảnh hưởng rất lớn nếu code của bạn cần 0. 04ms hoặc gần như 0. 08ms để tạo từ điển của bạn. Ngay cả khi bạn khởi tạo một từ điển trống, nó vẫn chậm hơn.

Danh sách tuple hoặc từ điển nào nhanh hơn?

Tạo bộ nhanh hơn tạo danh sách . Tạo danh sách chậm hơn vì cần truy cập hai khối bộ nhớ. Một phần tử trong bộ không thể bị xóa hoặc thay thế. Một phần tử trong danh sách có thể được loại bỏ hoặc thay thế.

Từ điển có chiếm nhiều dung lượng hơn danh sách không?

Từ điển chiếm nhiều không gian hơn so với danh sách các bộ dữ liệu . Ngay cả một lệnh trống cũng chiếm nhiều không gian so với một danh sách các bộ dữ liệu.

Chủ Đề