Answer the question
In order to leave comments, you need to log in
What is the algorithm for fetching data from a Python list?
Colleagues, tell a beginner about a possible algorithm for retrieving (receiving) data from a Python list, which can contain both dictionaries, tuples, lists ...) using a loop. I have a misunderstanding with referring to nested structures, I just can’t understand the principle ....
For example, there is such a list:
s_list = [
{'one': 1, 'two': 2, 'seven': 7, 'fix': 'price', 'number': [5, 4, 2, 3, 5, 4], 'dig': 4},
{'one': 5, 'two': 4, 'seven': 6, 'fix': 'nix', 'number': [3, 5, 7, 2, 3, 9], 'dig': 5},
{'one': 8, 'two': 3, 'seven': 9, 'fix': 'pix', 'number': [3, 2, 3, 1, 8, 4], 'dig': 9}
]
print(s_list[0]['number'])
for x in s_list():
???
Answer the question
In order to leave comments, you need to log in
s_list = [
{'one': 1, 'two': 2, 'seven': 7, 'fix': 'price', 'number': [5, 4, 2, 3, 5, 4], 'dig': 4},
{'one': 5, 'two': 4, 'seven': 6, 'fix': 'nix', 'number': [3, 5, 7, 2, 3, 9], 'dig': 5},
{'one': 8, 'two': 3, 'seven': 9, 'fix': 'pix', 'number': [3, 2, 3, 1, 8, 4], 'dig': 9}
]
for i, item in enumerate(s_list):
print('\nItem #', i, ':')
for key in item:
print(key, '=', item[key])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question