#filtering multiple lists in 1 go using filter()

22 messages · Page 1 of 1 (latest)

radiant owl
#

how should i go about doing this? trying to make it as simple as possible.

radiant owl
#

i would just do something like this, but idk how to remove duplicates : ```py
posts = [{...}, {...}, {...}]
filtered_posts = []

filtered_posts.extend(list(filter(lambda x: x['test'] == True, posts)))
filtered_posts.extend(list(filter(lambda x: x['test1'] == True, posts)))
filtered_posts.extend(list(filter(lambda x: x['test2'] == True, posts)))```

radiant owl
#

this gives me an error : ```py
posts = res['data']['children'][1: 24]
filtered_posts = []

    filtered_posts.extend(list(filter(check_nsfw, posts)))
    filtered_posts.extend(list(filter(check_videos, posts)))
    filtered_posts.extend(list(filter(check_gallerys, posts)))
      
    filtered = list(set(filtered_posts))

``` TypeError: unhashable type: 'dict' i really dont wanto have to iterate through everything, is there anything else i can do?

#

i fixed that but it still dosent work, my filteres are not working properly for some reason

rain girder
kind saffron
#

I think a for loop would be cleaner way to do this, and that way you can check the duplicates, other way is to use a set.

radiant owl
#

because my functions are not as simple as what i have sent so i cannot do what you sent

rain girder
#
for tests in [your tests]
radiant owl
#

i know

#

but either way i still have an issue removing the duplicates

#

since the list with duplicates is a list of dicts

#

so i cant use list(set([{...}, {...}]))

rain girder
#

You want to get rid of duplicates in a dictionary?

#

Or...?

rain girder
radiant owl
#

no

#

the list after all filtering should contain duplicates of some dicts

#

i need to remove those

rain girder
#

Can you give an example on what you are trying to do

radiant owl
#

filter a list 3 times, using 3 diff functions