TheBajan_israelian
TheBajan_israelian

Reputation: 35

how do I convert the first part of JSON into an array python?

example

{'1':'e1','2':'e2','3':'e3'}

I am wondering if there is a way to isolate the name of the variables into an array of ['1','2','3'], in python.

Upvotes: 0

Views: 29

Answers (2)

Kurt Kline
Kurt Kline

Reputation: 2069

All you need is list(d)

d = {'1':'e1','2':'e2','3':'e3'}

print(list(d)) # -> ['1', '2', '3']

Upvotes: 1

Yaniv
Yaniv

Reputation: 829

In python: if d = {'1':'e1','2':'e2','3':'e3'}, then list(d.keys()) will give you ['1', '2', '3'].

Upvotes: 1

Related Questions