且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

python获取列表并仅在使用set也存在负值时才返回

更新时间:2023-12-05 17:54:40

如果您从使用 big_list() 创建的列表中创建 set,则可以使用它来通过遍历集合的所有元素并选择所有值大于 0 且负值也在集合中的元素来创建所需的结果列表.

If you create a set from a list created with big_list(), you can use it to create a desired result list by iterating through all the elements of the set and selecting all those whose values are > 0 and whose negative value is also in the set.

您可以使用列表显示表达式,通常称为列表推导式",用于在 [] 括号内创建带有一行长代码的结果列表,就像 big_list() 函数一样.

You can use a list display expression, commonly call a "list comprehension", to create the resultant list with one long-ish line of code inside [] brackets, like the big_list() function does.

希望这会有所帮助.