python - Inserting values to nested dictionaries -


I have some nested direct Pyrenees and I need some help to get my code working perfectly.

First Code:

  data = {} def insertIntoDataStruct (country, state, job, count, dict): if the word in the country: word [country] [state] = {Job: counting} alif not in country: word [country] = {state: {job: counting}} not alif state [country]: word [country] = {state: {job: count}} no alif job [Word] [state]: [country] [state] [job] = counting rest: word [country] [state] [job] + = countIndetatstruct ("US", "Texas", 1234, 1, data) insertIntoDataStruct ("(" US "," TX ", 12345, 1, Day InsertIntoDataStruct ("US", "MI", 1234, 1, data) insertIntoDataStruct ("IN", "M") insertIntoDataStruct ("IN", "Kerala", 1234, 1, data) , 1234, 1, data) Print Data   

Currently printing this:

  {'US': {'MI': { 1234: 1}, 'TX': {12345: 1}}, 'IN': {'M': {1234: 1}, 'Kerala': {1234: 1}}}  

Its external word, country, internal level, states, internal level, job is a dictionary: Calculation

The counting is not working correctly Kerala should be 2 in 1234, and then itProgrammed anything appears, he is transferred to the location of any State to the latest state that is already in the dictionary. For example TX 1234 does not show because it was later replaced by TX 12345

Thanks in advance for all help! Your country does not want any fix, try it:

  def insertIntoDataStruct (country, state, job, Country] [state] = [Job: count] [state] [Job]: [country] = {state: {Job: count}} Elif not the state [country]: [country] [state] = [Job: count] = Counting rest: word [country] [state] [job] + = counting  

what is this originally, if the country does not exist, then make it, otherwise if the state does not exist Is, etc ...

doing this Another way of doing this is by default: defaultdict :

  is importable from the archive, counter jobdict = default dict (lambda: default duty) jobsdict ['US'] [ 'TX'] ['1234'] + = 1  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -