Python data structure that accepts a combination of <non_substring_key, value> as unique
Python dictionaries accept key as unique. But I'm struggling to write (find) a DS that supports the following:
Example 1 :
|------|-----------------| | abc | matched in abcD | |------|-----------------| | match| matched in abcD | |------|-----------------| | abc | abc found again | if the following entry appears as:
|-----|-----------------| | abcd| matched in abcD | ----> should replace first entry because abc is substring of abcd. So the records / table should look like
|------|-----------------| | abcd | matched in abcD | |------|-----------------| | match| matched in abcD | |------|-----------------| | abc | abc found again | Any suggestions?
possible function definition
def substring_value_confirm(keys, values): # implement as above return required_mapping substring_value_confirm(["abc","match","abc","abcd"],["matched in abcD", "matched in abcD", "abc found again", "matched in abcD"]) for any new record, value should first be matched, if value exists, then key will be checked if one key is a substring of another, and then longer to get a place.
Example 2:
|------|----| | a | 1 | |------|----| | b | 2 | |------|----| | ba | 3 | if new entries
|------|----| | ab | 1 | ----> should replace first |------|----| | b | 2 | ----> should be discarded because already present |------|----| | ab | 3 | ----> will be new insertion So the result / result table:
|------|----| | ab | 1 | |------|----| | b | 2 | |------|----| | ba | 3 | |------|----| | ab | 3 | +5
No one has answered this question yet.
See related questions: