Python Forum
Problem in list manipulation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem in list manipulation
#4
I get the same results if my_list is a list or a BindableList. The problem is that everything you added to the list is the same; o1 == o2 == o3. The reason they are all the same is because they are all empty lists.

If you want to remove items based on the item ID or the name, you need to override some comparison operators in BindableList. These use _name when comparing <, >. ==.
class BindableList(Bindable, list):
    ITEM_APPENDED = "<<ITEM_APPENDED>>"
    ITEM_REMOVED = "<<ITEM_REMOVED>>"
    ITEM_INSERTED = "<<ITEM_INSERTED>>"
 
    def __gt__(self, other):
        return self._name > other._name

    def __lt__(self, other):
        return self._name < other._name

    def __eq__(self, other):
        return self._name == other._name

    def append(self, __object) -> None:
        super().append(__object)
        self.event_generate(BindableList.ITEM_APPENDED, __object)
 
    def remove(self, __value) -> None:
        super().remove(__value)
        self.event_generate(BindableList.ITEM_REMOVED, __value)
 
    def insert(self, __index: int, __object) -> None:
        super().insert(__index, __object)
        self.event_generate(BindableList.ITEM_INSERTED, (__index, __object))
Reply


Messages In This Thread
Problem in list manipulation - by CyKlop - Oct-17-2021, 04:41 PM
RE: Problem in list manipulation - by bowlofred - Oct-17-2021, 09:00 PM
RE: Problem in list manipulation - by CyKlop - Oct-17-2021, 09:54 PM
RE: Problem in list manipulation - by deanhystad - Oct-18-2021, 03:42 AM
RE: Problem in list manipulation - by CyKlop - Oct-18-2021, 04:27 AM
RE: Problem in list manipulation - by deanhystad - Oct-18-2021, 08:44 AM
RE: Problem in list manipulation - by DeaD_EyE - Oct-18-2021, 09:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with "Number List" problem on HackerRank Pnerd 5 2,224 Apr-12-2022, 12:25 AM
Last Post: Pnerd
  optimization problem for dataframe manipulation fimmu 0 1,520 Aug-31-2020, 06:02 PM
Last Post: fimmu
  How to pass a list by value for manipulation within a process? bRitch022 4 2,825 Jul-09-2020, 07:13 PM
Last Post: bRitch022
  IP string manipulation problem TheRealNoob 12 7,552 Feb-04-2019, 09:29 AM
Last Post: perfringo
  list manipulation cameronwood611 3 3,664 Oct-03-2017, 02:58 PM
Last Post: ichabod801
  list or dictionary manipulation dtigue 5 123,506 Jul-21-2017, 03:14 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020