Created
September 11, 2019 15:42
-
-
Save meysampg/4da378af3b650c85575cf63a50db4418 to your computer and use it in GitHub Desktop.
remove similar key from a dictionary and put the longest key as the final key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def removeSimilarKeyFromDictionary(d, key): | |
for s in d.keys(): | |
if key.find(s) != -1: | |
# True with a non-empty list mean the given key is the final key, but it has a candidate on list | |
return True, s | |
elif s.find(key) != -1: | |
# False with a non-empty list mean the iterator key is the final key and its value should sum with | |
# the value of returned key | |
return False, s | |
# False with an empty list mean the given key has no candidate on the list | |
return False, None |
Author
meysampg
commented
Sep 11, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment