Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Bàn luận
This task can be performed using a “=” operator. In this we just ensure enough variables as the count of list elements and assign them to list, the list elements get allotted to variables in order of their assignment.
Đôi khi, trong khi làm việc với danh sách, chúng ta có thể có một mong muốn có từng yếu tố danh sách được chuyển đổi hoặc giải nén thành các biến bắt buộc. Vấn đề này có thể xảy ra trong miền phát triển web. Hãy để thảo luận về những cách nhất định trong đó vấn đề này có thể được giải quyết.
Phương pháp số 1: Sử dụng nhiệm vụ "=" operator
này có thể được thực hiện bằng cách sử dụng toán tử = = Trong đó, chúng tôi chỉ đảm bảo đủ các biến vì số lượng của các yếu tố danh sách và gán chúng vào danh sách, các yếu tố danh sách được phân bổ cho các biến theo thứ tự nhiệm vụ của chúng.
test_list
=
[
1
,
3
____7
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 2010____7__12
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 26
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 27
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 28
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 29
"=" operator
0"=" operator
1"=" operator
2=
"=" operator
4
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 26
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 27
"=" operator
7 The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 29
test_list
3
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 29
"=" operator
0test_list
6The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 29
test_list
2test_list
3
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 29
"=" operator
0=
2The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 29
test_list
2test_list
3The original list is : [1, 3, 7, 4, 2]
Variables as assigned are : 1 3 7 4 2
9 "=" operator
0=
8The original list is : [1, 3, 7, 4, 2]
Variables as assigned are : 1 3 7 4 2
9 test_list
2
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 2
test_list
3The original list is : [1, 3, 7, 4, 2]
Variables as assigned are : 1 3 7 4 2
9 "=" operator
0[
4
This problem can be solved using a namedtuple, which can store the list elements with a variable name that can be accessed by using a dot operator succeeding with name of variable initialized.
Đầu ra:
Đôi khi, trong khi làm việc với danh sách, chúng ta có thể có một mong muốn có từng yếu tố danh sách được chuyển đổi hoặc giải nén thành các biến bắt buộc. Vấn đề này có thể xảy ra trong miền phát triển web. Hãy để thảo luận về những cách nhất định trong đó vấn đề này có thể được giải quyết.
Phương pháp số 1: Sử dụng nhiệm vụ "=" operator
này có thể được thực hiện bằng cách sử dụng toán tử = = Trong đó, chúng tôi chỉ đảm bảo đủ các biến vì số lượng của các yếu tố danh sách và gán chúng vào danh sách, các yếu tố danh sách được phân bổ cho các biến theo thứ tự nhiệm vụ của chúng.
test_list
=
[
1
,
3
____7
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 2010____7__12
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 26
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 27
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 28
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 29
"=" operator
0"=" operator
1"=" operator
2=
"=" operator
4
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 26
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 27
"=" operator
7 The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 29
test_list
3
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 29
"=" operator
0test_list
6The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 29
test_list
2test_list
3
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 29
"=" operator
0=
2The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 29
test_list
2test_list
3
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 29
"=" operator
0=
8The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 29
test_list
2test_list
3The original list is : [1, 3, 7, 4, 2]
Variables as assigned are : 1 3 7 4 2
9 "=" operator
0=
8The original list is : [1, 3, 7, 4, 2]
Variables as assigned are : 1 3 7 4 2
9 test_list
2
The original list is : [1, 3, 7, 4, 2] Variables as assigned are : 1 3 7 4 2