Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang list generation

Tags:

list

erlang

I have 2 list:

["asd", "dsa"].

[[123, "asd"], [4534, "fgh"]].

How can i generate next list: I ned list that tail of each nested list =:= other element of 1 list.

In this example:

["asd", "dsa"].

[[123, "asd"], [4534, "fgh"]].

"asd" =:= "asd" ->

Output list:

[123, "asd"] 

I try:

Here S = [[123, "asd"], [4534, "fgh"]]. D = ["asd", "dsa"].

List = lists:filter(fun(X) -> lists:last(X) =:= D end, S),

But D in this example list, and i need element of list.

How can do it?

like image 706
0xAX Avatar asked Jul 17 '26 14:07

0xAX


1 Answers

Maybe something like:

1> [X || X<-[[1,2,4],[7,8,3],[2,5,4],[9,1,6]], Y<-[4,3], lists:last(X)=:=Y].    
[[1,2,4],[7,8,3],[2,5,4]]

Or, using your sample data:

2> [X || X<-[[123,"asd"], [4534,"fgh"]], Y<-["asd","dsa"], lists:last(X)=:=Y].
[[123,"asd"]]
like image 110
YasirA Avatar answered Jul 19 '26 08:07

YasirA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!