Skip to content
Advertisement

Converting list of dictionary to list of lists

I have list of dictionary like below

dictList = [{'key': 'ABORT_DETACHED_QUERY', 'value': 'false'}, {'key': 'ALLOW_CLIENT_MFA_CACHING', 'value': 'false'}, {'key': 'ALLOW_ID_TOKEN', 'value': 'false'}]

I want to convert it like below

List1= [['ABORT_DETACHED_QUERY', 'false'], ['ALLOW_CLIENT_MFA_CACHING', 'false'], ['ALLOW_ID_TOKEN', 'false']]

Appreciate your help !

Advertisement

Answer

You can use list comprehension, where you iterate each dictionary in the list, and get the list of values only for each dictionary:

List1 = [[*item.values()] for item in dictList]

OUTPUT:

[['ABORT_DETACHED_QUERY', 'false'], ['ALLOW_CLIENT_MFA_CACHING', 'false'], ['ALLOW_ID_TOKEN', 'false']]
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement