0

Input:

a_list = [x,y,z,p,q,r] value = 5 

Output:

dict1 = {x: {y : {z : { p :{ q :{ r : 5}}}}} 
1
  • 8
    How does the config file relate to the list->dict? Commented Mar 21, 2018 at 5:34

1 Answer 1

1

Progressively construct nested dictionaries, starting with the single value:

from functools import reduce dict1 = reduce(lambda d,key: {key : d}, a_list[::-1], value) print(dict1) #{'x': {'y': {'z': {'p': {'q': {'r': 5}}}}}} 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.