Open anancds opened 4 years ago
expression1 if condition else expression2 for item in iterable 相当于:
for item in iterable: if condition: expression1 else: expression2
而如果没有 else 语句,则需要写成:expression for item in iterable if condition
[(xx, yy) for xx in x for yy in y if xx != yy] 相当于:
l = [] for xx in x: for yy in y: if xx != yy: l.append((xx, yy))
expression1 if condition else expression2 for item in iterable 相当于:
for item in iterable: if condition: expression1 else: expression2