name, value):
... self.id = id
... self.name = name
... self.value = value
...
>>> m_list = [My(1,"test1","sllsfll"), My(2,"test2", "feklfkslkfelsk") ]
>>> m_list
[<__main__.My object at 0x000001EBC3CBC048>, <__main__.My object at 0x000001EBC3E0DBC8>]
>>> values = { 1 : "sllsfll", 2 : "feklfkslkfelsk"}
>>> values
{1: 'sllsfll', 2: 'feklfkslkfelsk'}
>>> for vk, vl in values.items():
... print(filter(lambda x: x.id == vk, m_list))
...
<filter object at 0x000001EBC3E0DE88>
<filter object at 0x000001EBC3E0DE48>
>>> for vk, vl in values.items():
... print(filter(lambda x: x.id == vk, m_list).name)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
AttributeError: 'filter' object has no attribute 'name' how i can to do this correctly?
подскажите по-моему вопросу плз, я с другого языка пришел :D
Обсуждают сегодня