Mar-03-2018, 11:06 AM
dTeamNames = {'A': 'Man City', 'B': 'Man United', 'C': 'West Brom', 'D': 'West Ham' }Hello:
I have a dictionary contains a key and a team name as the example above.
Now, I want to find a way to create another dictionary which uses the same key as dTeams, but use only the shortest length of string of the original team names as the value.
For example, I want to have the following new dictionary using the above dTeamNames:
dShortNames = {'A': 'Man Ci', 'B': 'Man Un', 'C': 'West B', 'D': 'West H' }The rule is: for the minimum length of string which can tell the difference for each team names.
For “Man City” and “Man United”, the minimum length is 5, so I can use “Man C” and “Man U” to differentiate the both team names; however, for “West Brom” and “West Ham”, the minimum length is 6, so I can use “West B” and “West H” to differentiate the both team names.
I want to write a function to find how to find the minimum length of string to differentiate all the team names in the dictionary and create the new dictionary.
Thanks for advice.
John