PointsListDictionaryBasicsList đề cập đến tập hợp các mảng giống như cặp giá trị chỉ mục trong C/C++/Java. Từ điển đề cập đến cấu trúc băm của các cặp khác nhau như cặp khóa-giá trị. CreationList được khởi tạo với [] và các phần tử được phân tách bằng ','. Từ điển được tạo bằng cách đặt các thành phần trong {}, dữ liệu được thêm dưới dạng cặp khóa-giá trị và mỗi cặp được phân tách bằng ','. Các giá trị AccessingList có thể được truy cập bằng các chỉ mục số. Các mục từ điển có thể được truy cập bằng cách sử dụng các giá trị chính. Các giá trị khóa có thể thuộc bất kỳ loại dữ liệu nào. Thứ tự các phần tử Thứ tự các phần tử trong danh sách luôn được duy trì. Chúng tôi không có bất kỳ đảm bảo nào về việc duy trì thứ tự của các yếu tố có sẵn. PropertiesList được sắp xếp, có thể thay đổi và cho phép các giá trị trùng lặp. Trong một từ điển, từ điển không có thứ tự và có thể thay đổi, nhưng từ điển không cho phép các giá trị trùng lặp có cùng khóa trong đó. Lưu trữ dữ liệuDanh sách được sử dụng để lưu trữ dữ liệu, dữ liệu này phải được sắp xếp theo thứ tự và tuần tự. Nó lưu trữ một lượng lớn dữ liệu để truy cập dễ dàng và nhanh chóng
Ví dụ về danh sách và từ điển trong Python
ví dụ 1. Tạo và truy cập các giá trị của danh sách và từ điển trong Python
Mã số
# create a list l1 = ['I', 'like', 'Apple'] # print the list with multiple values. It is the same as a 1D array in C, and C++. print[l1[0]] print[l1[1]] print[l1[2]] # create a list with multiple dimensions, like a 2D array. l2 = [["I"], ["love"], ["chinese", "italian", "indian"]] # print the list l2, showing the multiple dimension, i.e., 2D. print[l2] print[l2[0]] print[l2[1]] print[l2[2]] print[l2[1][0]]
đầu ra
I like Apple [['I'], ['love'], ['chinese', 'italian', 'indian']] ['I'] ['love'] ['chinese', 'italian', 'indian'] love
Giải trình
Mã python sau đây cho chúng ta biết cách triển khai danh sách, cách truy cập các mục trong danh sách bằng chỉ mục số và nhiều chiều của danh sách
Đầu vào
# create a dict with numeric keys. While accessing the elements of d1, it looks like a list, but it is a dictionary. d1 = { 1 : "I", 2 : "like", 3 : "apple" } print["Dictionary with numeric keys:"] print[d1[1]] print[d1[2]] print[d1[3]] # dict with non-numeric keys d2 = { "Fruit" : "Apple", "King_of_fruits" : "Mango", "Seasonal_fruit" : "Strawberry" } print["Dictionary with non-numeric keys"] print[d2["Fruit"]] print[d2["King]of_fruits"]] print[d2["Seasonal_fruit"]]
đầu ra
Dictionary with numeric keys: I like apple Dictionary with non-numeric keys Apple Mango Strawberry
Giải trình. Trong mã python sau đây, chúng ta đã thấy rằng từ điển mất ít thời gian hơn so với danh sách. Danh sách mất nhiều thời gian hơn để tìm nạp một phần tử từ danh sách so với từ điển vì từ điển sử dụng bảng băm để triển khai sắp xếp
# Lists
7=
# Lists
9# Creating a List with
0_______121_______1Time taken by dictionary: 9.5367431640625e-07 Time taken by list: 4.76837158203125e-079Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}2Time taken by dictionary: 9.5367431640625e-07 Time taken by list: 4.76837158203125e-071# Creating a List with
1# Python program to demonstrate
1Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}2# Creating a List with
8# Creating a List with
1Time taken by dictionary: 9.5367431640625e-07 Time taken by list: 4.76837158203125e-079# the use of multiple values
1Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}7Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}8# the use of multiple values
4Accessing dictionary elements: 1 2 Time taken by dictionary: 1.0013580322265625e-05 Accessing List elements: 1 2 Time taken by dictionary: 3.5762786865234375e-060Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}7Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}8# Lists
7Accessing dictionary elements: 1 2 Time taken by dictionary: 1.0013580322265625e-05 Accessing List elements: 1 2 Time taken by dictionary: 3.5762786865234375e-060Time taken by dictionary: 9.5367431640625e-07 Time taken by list: 4.76837158203125e-073
# Lists
5
List
2
# Lists
7=
# Lists
9List
6# Creating a List with
1Time taken by dictionary: 9.5367431640625e-07 Time taken by list: 4.76837158203125e-079Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}2# Creating a List with
0=
1# Creating a List with
0Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}2Time taken by dictionary: 9.5367431640625e-07 Time taken by list: 4.76837158203125e-071Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}2# Creating a List with
8Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}2=
8_______119_______Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}7Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}8Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}02Accessing dictionary elements: 1 2 Time taken by dictionary: 1.0013580322265625e-05 Accessing List elements: 1 2 Time taken by dictionary: 3.5762786865234375e-060Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}7Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}8# Lists
7Accessing dictionary elements: 1 2 Time taken by dictionary: 1.0013580322265625e-05 Accessing List elements: 1 2 Time taken by dictionary: 3.5762786865234375e-060đầu ra
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}
Sự khác biệt giữa Danh sách và Từ điển
ListDictionaryList là tập hợp các cặp giá trị chỉ số như của mảng trong C++. Từ điển là một cấu trúc băm của các cặp khóa và giá trị. Danh sách được tạo bằng cách đặt các phần tử trong [ ] được phân tách bằng dấu phẩy “, “Từ điển được tạo bằng cách đặt các phần tử trong { } làm “khóa”. “giá trị”, mỗi cặp giá trị khóa được phân tách bằng dấu phẩy “, “Các chỉ số của danh sách là các số nguyên bắt đầu từ 0. Các khóa của từ điển có thể thuộc bất kỳ loại dữ liệu nào. Các yếu tố được truy cập thông qua các chỉ số. Các phần tử được truy cập thông qua khóa-giá trị. Thứ tự của các phần tử đã nhập được duy trì. Không có gì đảm bảo cho việc duy trì trật tự
Đánh đổi không gian-thời gian
Sẽ hiệu quả hơn khi sử dụng từ điển để tra cứu các phần tử vì mất ít thời gian hơn để duyệt qua từ điển so với danh sách
Ví dụ: hãy xem xét một tập dữ liệu có 5000000 phần tử trong mô hình học máy dựa trên tốc độ truy xuất dữ liệu. Để thực hiện điều này, chúng ta phải lựa chọn một cách khôn ngoan giữa hai cấu trúc dữ liệu i. e. danh sách và từ điển. Từ điển được ưa thích hơn vì ít thời gian hơn và dung lượng lưu trữ ít hơn vì từ điển được triển khai dưới dạng bảng băm từ python3. 6 vì vậy nó không bao giờ là vấn đề đánh đổi không-thời gian trong từ điển
ví dụ 1
Python3
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}08Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}09Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}10
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}11Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}12Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}13Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}14
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}15Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}16=
# Lists
9Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}19_______121_______1# Creating a List with
0Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}2Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}23# Creating a List with
1Time taken by dictionary: 9.5367431640625e-07 Time taken by list: 4.76837158203125e-071# the use of multiple values
1
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}27=
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}29
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}30Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}7Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}8Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}33Accessing dictionary elements: 1 2 Time taken by dictionary: 1.0013580322265625e-05 Accessing List elements: 1 2 Time taken by dictionary: 3.5762786865234375e-060Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}35Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}36Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}37Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}38 Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}39Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}7Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}41=
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}43Accessing dictionary elements: 1 2 Time taken by dictionary: 1.0013580322265625e-05 Accessing List elements: 1 2 Time taken by dictionary: 3.5762786865234375e-060
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}45=
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}29Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}7Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}8Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}50_______5_______51_______5_______52Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}53
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}54Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}55=
___Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}0# Creating a List with
0Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}2Time taken by dictionary: 9.5367431640625e-07 Time taken by list: 4.76837158203125e-071Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}6
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}27=
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}29
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}7Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}8Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}67Accessing dictionary elements: 1 2 Time taken by dictionary: 1.0013580322265625e-05 Accessing List elements: 1 2 Time taken by dictionary: 3.5762786865234375e-060Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}35Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}70_______5_______37Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}72Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}39Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}7Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}75=
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}43Accessing dictionary elements: 1 2 Time taken by dictionary: 1.0013580322265625e-05 Accessing List elements: 1 2 Time taken by dictionary: 3.5762786865234375e-060Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}39Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}45=
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}29Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}7Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}8Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}50_______5_______51_______5_______52Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}53đầu ra
Accessing dictionary elements: 1 2 Time taken by dictionary: 1.0013580322265625e-05 Accessing List elements: 1 2 Time taken by dictionary: 3.5762786865234375e-06ví dụ 2
Python3
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}89Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}90
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}13Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}14
Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}93Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}94=
# Lists
9Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}97_______121_______1Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}99Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}2Accessing dictionary elements: 1 2 Time taken by dictionary: 1.0013580322265625e-05 Accessing List elements: 1 2 Time taken by dictionary: 3.5762786865234375e-0601# Creating a List with
1Accessing dictionary elements: 1 2 Time taken by dictionary: 1.0013580322265625e-05 Accessing List elements: 1 2 Time taken by dictionary: 3.5762786865234375e-0603# the use of multiple values
1Accessing dictionary elements: 1 2 Time taken by dictionary: 1.0013580322265625e-05 Accessing List elements: 1 2 Time taken by dictionary: 3.5762786865234375e-0605=
5_______0Time taken by dictionary: 9.5367431640625e-07 Time taken by list: 4.76837158203125e-071_______5_______2# Creating a List with
8Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}2=
8Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}2Accessing dictionary elements: 1 2 Time taken by dictionary: 1.0013580322265625e-05 Accessing List elements: 1 2 Time taken by dictionary: 3.5762786865234375e-0614Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}2# Creating a List with
0Dictionary with the use of Integer Keys: {1: 'Geeks', 2: 'For', 3: 'Geeks'} Dictionary with the use of Mixed Keys: {1: [1, 2, 3, 4], 'Name': 'Geeks'}6Sự khác biệt giữa chuỗi và danh sách trong Python là gì?
A Series là mảng một chiều được gắn nhãn có khả năng chứa bất kỳ loại dữ liệu nào [số nguyên, chuỗi, số dấu phẩy động, đối tượng Python, v.v. ]. Cần phải nhớ rằng không giống như danh sách Python, a Chuỗi sẽ luôn chứa dữ liệu cùng loại .Sự khác biệt giữa sê-ri và DataFrame trong Python là gì?
Sê-ri chỉ có thể chứa một danh sách có chỉ mục, trong khi khung dữ liệu có thể được tạo thành từ nhiều chuỗi hoặc chúng ta có thể nói rằng khung dữ liệu là một tập hợp các chuỗi có thể được sử dụng để .Sự khác biệt giữa danh sách và từ điển trong Python là gì?
Cả hai đều là công cụ được sử dụng trong ngôn ngữ Python, nhưng có một sự khác biệt quan trọng giữa Danh sách và Từ điển trong Python. Danh sách đề cập đến một tập hợp các cặp giá trị chỉ số khác nhau giống như trường hợp của một mảng trong C++. Từ điển đề cập đến cấu trúc được băm gồm nhiều cặp khóa và giá trị khác nhau .Là một loạt gấu trúc một từ điển?
Pandas Series là một mảng dữ liệu được lập chỉ mục một chiều. Nó có thể được tạo bằng cách sử dụng một danh sách hoặc một mảng. Dòng Pandas có thể được coi là một trường hợp đặc biệt của từ điển Python . Đó là một cấu trúc ánh xạ các khóa đã nhập thành một tập hợp các giá trị đã nhập.