1

How can one extract a list of keys and a list of values from the association?

e.g. as = <|a->1, b->2, c->3, d->4|>

lst1 = {a, b, c, d}
lst2 = {1, 2, 3, 4}

Thanks!

SuTron
  • 1,708
  • 1
  • 11
  • 21
  • I have marked this as a duplicate as though this is a special case I feel everyone is better served by the redirect rather than closure. The association can be converted to rules with Normal, then any of the methods given there may be used. Or you can just use Keys and Values directly. – Mr.Wizard Apr 30 '15 at 19:12

1 Answers1

3
lst1 = Keys @ as
lst2 = Values @ as
{a, b, c, d}
{1, 2, 3, 4}

Or

{lst1, lst2} = Transpose @ KeyValueMap[List, as];

lst1
lst2
{a, b, c, d}
{1, 2, 3, 4}
Karsten7
  • 27,448
  • 5
  • 73
  • 134