Skip to content

Commit 294debc

Browse files
committed
优化for循环减少indent层次
1 parent 1abe435 commit 294debc

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

for.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""优化前"""
2+
for item in items:
3+
if is_for_sale(item):
4+
cost = compute_cost(item)
5+
if cost <= wallet.money:
6+
buy(item)
7+
8+
"""优化后"""
9+
for item in items:
10+
if not is_for_sale(item):
11+
continue
12+
cost = compute_cost(item)
13+
if cost > wallet.money:
14+
continue
15+
buy(item)

0 commit comments

Comments
 (0)