1

I want to split this tuple into:

 {d,[{{1,c},{2,g}},{{3,f},{4,f}}]}

  a = [1,c],[2,g]  
  b = [3,f],[4,f]

where a and b are just variable

I tried looking at extraction of elements of tuples

But not able to split it like that I want.

Any help will be appreciated.

Community
  • 1
  • 1
kyle
  • 103
  • 1
  • 8

1 Answers1

4

Assuming first element of the tuple doesn't matter, and the second is always a two-element list:

{_, [A0, B0]} = {d,[{{1,c},{2,g}},{{3,f},{4,f}}]},

and that you want to get A and B as lists (you can't have a and b as variables in Erlang):

A1 = tuple_to_list(A0), %% [{1,c},{2,g}],
A = lists:map(fun tuple_to_list/1, A1),
%% similarly for B
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487