Python Forum
Remove empty keys in a python list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove empty keys in a python list
#7
That error trace is not for the code you posted.

Your error is dictionary does not have a method named "value", it has "values".

I think you can do this as a one liner. Well two one liners.
if isinstance(payload, list):
    payload = [d for d in payload if not "" in d["payload"].values()]
else:
    payload = {k:v for k, v in payload.items() if v != ""}
I still think a more generic solution is better.
Reply


Messages In This Thread
RE: Remove empty keys in a python list - by deanhystad - Jan-11-2022, 10:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python automation: Sending clicks/keys to VMware virtual machine from host olips784 0 384 May-18-2025, 06:28 PM
Last Post: olips784
  remove duplicates from dicts with list values wardancer84 27 6,777 May-27-2024, 04:54 PM
Last Post: wardancer84
  what to return for an empty list Skaperen 2 1,364 May-24-2024, 05:17 PM
Last Post: Skaperen
  unable to remove all elements from list based on a condition sg_python 3 1,834 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Code with empty list not executing adeana 9 6,147 Dec-11-2023, 08:27 AM
Last Post: buran
  Remove numbers from a list menator01 4 4,003 Nov-13-2022, 01:27 AM
Last Post: menator01
  set.difference of two list gives empty result wardancer84 4 2,738 Jun-14-2022, 01:36 PM
Last Post: wardancer84
  Updating nested dict list keys tbaror 2 2,054 Feb-09-2022, 09:37 AM
Last Post: tbaror
  displaying empty list vlearner 5 3,166 Jan-19-2022, 09:12 AM
Last Post: perfringo
  Remove an item from a list contained in another item in python CompleteNewb 19 9,313 Nov-11-2021, 06:43 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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