Home > other >  On the list in python, dict search problem
On the list in python, dict search problem

Time:09-24


As shown, variable load_dict type data is a list in each data are a dict data dictionary, I want to find a word value=I given the word in the dictionary of data, with no correlation function method can be called directly

CodePudding user response:

To build a large dictionary, need not function, can be directly read a dictionary,
Example for small section for your reference
 

Dict_list=[
{' word ':' king 'and' pingyin ':' wang '},
{' word ':' li ', 'pingyin' : 'li'},
{' word ':' zhao ', 'pingyin' : 'zhao'},
{' word ':' money ', 'pingyin' : 'qian'}
]

Dict_list_new={}
For d in dict_list:
Dict_list_new [' word '] [d]=d

Print (dict_list_new [' king '])
Print (dict_list_new [' zhao '])




CodePudding user response:

reference 1/f, old coconut response:
to build a large dictionary, need not function, can be directly read a dictionary,
Example for small section for your reference
 

Dict_list=[
{' word ':' king 'and' pingyin ':' wang '},
{' word ':' li ', 'pingyin' : 'li'},
{' word ':' zhao ', 'pingyin' : 'zhao'},
{' word ':' money ', 'pingyin' : 'qian'}
]

Dict_list_new={}
For d in dict_list:
Dict_list_new [' word '] [d]=d

Print (dict_list_new [' king '])
Print (dict_list_new [' zhao '])


Thank you ~

CodePudding user response:

The filter function can satisfy your needs

CodePudding user response:

reference chuifengde reply: 3/f
filter function can satisfy the demand of you

Problem has been resolved, but still thank you for your answer! A new way to learn
  • Related