1

I'd like to remove the list of dictionaries elements that have empty values.

So for the following:

dict = [{"end": "00:15", "item": "Paul Test 1", "start": "00:00"}, {"end": "00:14", "item": "Paul Test 2 ", "start": "00:30"}, {"end": "", "item": "", "start": ""},  {"end": "", "item": "", "start": ""}, {"end": "", "item": "", "start": ""}]

would return a new dict of:

[{"end": "00:15", "item": "Paul Test 1", "start": "00:00"}, {"end": "00:14", "item": "Paul Test 2 ", "start": "00:30"}]

I've tried:

{k:v for k,v in dict if not v}

but I'm getting:

ValueError: too many values to unpack (expected 2)

1 Answer 1

6

Try this:

print([d for d in arr if all(d.values())])

Don't use dict as a name: you override Python's one. And in your case it's not a dictionary, it is an array of dictionaries.

Sign up to request clarification or add additional context in comments.

3 Comments

You should use d.values() since the keys are not used.
Brilliant that's worked thanks. One question though, I thought arrays contained parenthesis and lists contained square brackets?
ah forgive me, I was getting arrays confused with tuples.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.