开发者

problem: how to verify affiliation of object in the collection of objects

I have a collection of objects. Objects are instance of the same class. I need to verify that the variable reviewed_object_name occurs in the object_name field of any object in the collection.

When I have a simple collection the solution is obvious:

reviewed_object_name = "Hotel Roma"
reviewed_objects_collection = ["Hotel Roma", "Hotel Berlin", "Hotel Paris", "Hotel Madrit"]

reviewed_object_name in reviewed_objects_collection

expression returns True

The problem arises when I have a collection of objects

I tried to do this using lambda:

some_function (re开发者_开发知识库viewed_objects_collection, key = lambda review_object_info: review_object_info.name)

What function would be able to give me this information?


any() with a genex.

any(reviewed_object_name == reviewed_object.name for reviewed_object in reviewed_objects_collection)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜