Skip to content

Commit 73af748

Browse files
committed
feat: iterating dict list
1 parent d968506 commit 73af748

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
students = [
2+
{"name":"阿土"},
3+
{"name":"小李"}
4+
]
5+
6+
# 在学员列表中搜索指定的姓名
7+
find_name = "阿乐"
8+
9+
for stu_dict in students:
10+
print(stu_dict)
11+
if stu_dict["name"] == find_name:
12+
print("找到了 %s" % find_name)
13+
# 如果已经找到,就直接退出循环
14+
break
15+
else:
16+
# 如果希望在搜索列表时,所有的字典检查之后,都没有发现需要搜索的目标
17+
# 还希望得到统一的提示
18+
print("没有找到 %s" % find_name)
19+
print("循环结束")

0 commit comments

Comments
 (0)