LIst Comprehensions: References to the Components

前端 未结 4 2000
眼角桃花
眼角桃花 2021-02-15 14:34

In sum: I need to write a List Comprehension in which i refer to list that is being created by the List Comprehension.

This might not be something you need to do every d

4条回答
  •  我寻月下人不归
    2021-02-15 15:02

    I don't see why you need to do this in one go. Either iterate through the initial data first to eliminate duplicates - or, even better, convert it to a set as KennyTM suggests - then do your list comprehension.

    Note that even if you could reference the "list under construction", your approach would still fail because s is not in the list anyway - the result of some_function(s) is.

提交回复
热议问题