Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下 for 和 if 条件,for 循环后跟一个 if 条件,关于如何将它们组合在一行中的任何建议?
for x in ids: if x!=12345
for x in (i for i in ids if i!=12345): # do stuff In [37]: ids Out[37]: [12343, 12344, 12345, 12346, 12347, 12348] In [38]: for x in (i for i in ids if i!=12345): ....: print x ....: 12343 12344 12346 12347 12348