forum

Home / DeveloperSection / Forums / Multiple filters in list comprehension in Erlang

Multiple filters in list comprehension in Erlang

Anonymous User 2253 22-May-2015
Say I have a list that contains weather:

1> Weather = [{toronto, rain}, {montreal, storms}, {london, fog}, 
    {paris, sun}, {boston, fog}, {vancouver, snow}].
To get foggy places, I could do this:

2> FoggyPlaces = [X || {X, fog} <- Weather].
[london,boston]
Now I want to retrieve places that are both foggy and snowy. I tried this, but it retrieves only snowy places,

3> FoggyAndSnowyPlaces = [X || {X, fog} <- Weather, {X,snow} <- Weather].
[vancouver,vancouver]
where I was expecting [london,boston,vancouver].

How can I include multiple filters?

I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By