List
The order of values is important.
Using the 'list' function allows you to utilize the order of values and the listed words or numbers to access the values.
a_list = [1,5,6,3,2]
a_list.append(99)
a_list.append(992)
a_list.append(919)
a_list.append(399)
print(a_list)
a_list = [1,5,6,3,2]
result = a_list[:3]
print(result)
Dictionary
It stores values as key-value pairs.
a_dict = {'name' : 'bob', 'age' : 27}
result = a_dict['age']
print (result)
Result : 27
Dictional & List
a_dict = {'name' : 'bob', 'age' : 27, 'Friend' : ['Jay', 'Lisa']}
result = a_dict['Friend'][1]
print (result)
Result : Lisa
Practice
Get the reult of Science score from smith
people = [
{'name': 'bob', 'age': 20, 'score':{'math':90,'science':70}},
{'name': 'carry', 'age': 38, 'score':{'math':40,'science':72}},
{'name': 'smith', 'age': 28, 'score':{'math':80,'science':90}},
{'name': 'john', 'age': 34, 'score':{'math':75,'science':100}}
]
result = people[2]['score']['science']
print(result)
result : 90
I studied about the List and Dictionary functions. With lists, values are retrieved based on the order of the columns, whreas with dictionaries, values are retrieved based on string values. Both can be used, and they seem to be the most basic but important concepts.
'Study Note > Python' 카테고리의 다른 글
6. Set & tuples and list (0) | 2024.03.27 |
---|---|
5. Uses of [] {} () (0) | 2024.03.26 |
4. Function [Def] (0) | 2024.03.26 |
3. IF & loop (0) | 2024.03.25 |
1. Variable declaration and data types (0) | 2024.03.25 |