Python Forum
Searching through a list of dictionaries with a condition.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Searching through a list of dictionaries with a condition.
#3
(Sep-28-2018, 12:07 PM)ichabod801 Wrote: It's not overwriting, you are removing the last iteration before you add a new one. The pop method removes the last item of the list. You keep removing an item and adding an item (lines 31 + 32), so you end up with one item. Remove line 31 and it should work.

You can also remove line 25. The with statement on line 21 takes care of that.

On the contrary, by removing the pop method it still returns the last sample ID, the only difference is that it's repeated by the number of key-values there are in the dictionary i.e.
S01933-11 r480
S01933-11 r480
S01933-11 r480
S01933-11 r480
S01933-11 r480
S01933-11 r480
S01933-11 r480
S01933-11 r480
S01933-11 r480
Reply


Messages In This Thread
RE: Searching through a list of dictionaries with a condition. - by Mr_Keystrokes - Sep-28-2018, 03:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a list of dictionaries by the only dictionary key Calab 2 738 Apr-29-2024, 04:38 PM
Last Post: Calab
  unable to remove all elements from list based on a condition sg_python 3 584 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Access list of dictionaries britesc 4 1,213 Jul-26-2023, 05:00 AM
Last Post: Pedroski55
  select Eof extension files based on text list of filenames with if condition RolanRoll 1 1,605 Apr-04-2022, 09:29 PM
Last Post: Larz60+
  Searching in the list quest 4 1,635 Mar-02-2022, 10:30 AM
Last Post: quest
  function that returns a list of dictionaries nostradamus64 2 1,853 May-06-2021, 09:58 PM
Last Post: nostradamus64
  convert List with dictionaries to a single dictionary iamaghost 3 2,949 Jan-22-2021, 03:56 PM
Last Post: iamaghost
  Creating a list of dictionaries while iterating pythonnewbie138 6 3,391 Sep-27-2020, 08:23 PM
Last Post: pythonnewbie138
  Help accessing elements of list of dictionaries Milfredo 6 2,972 Sep-07-2020, 01:32 AM
Last Post: Milfredo
  Accessing values in list of dictionaries pythonnewbie138 2 2,206 Aug-02-2020, 05:02 PM
Last Post: pythonnewbie138

Forum Jump:

User Panel Messages

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