I need some kind of loop or filter that removes every entry that doesn't contain the string "id" in it.
someDict = { 'id1': [('id1'), ('book'), ('sauce'), ('pencil')],
'id2': [('id2'), ('id4'), ('id5'), ('pens') , ('id6'), ('stuff')],
'id3': [('id3'), ('id81'), ('van'), ('garage')]}
So after, it would look like this:
someDict = { 'id1': [('id1')],
'id2': [('id2'), ('id4'), ('id5'), ('id6')],
'id3': [('id3'), ('id81') ]}
I'm beyond stumped. I've been trying to figure this out for three hours. Any help would be greatly appreciated.
I tried this, but I'm not good with filters like these. It was supposed to remove everything in the dictionary that didn't have "id" in it, but it didn't work.
#someDict = { k : v for k, v in someDict.items() if 'id' in v }
Then I tried to figure out a loop, but couldn't get this working either.
for key, value in someDict.items():
for x in value:
if not "id" in x:
value.remove(x)```