Python词典将key
视为唯一。但我正在努力编写(找到)支持以下内容的DS:
示例1 :
|------|-----------------|
| abc | matched in abcD |
|------|-----------------|
| match| matched in abcD |
|------|-----------------|
| abc | abc found again |
如果下一个条目如下:
|-----|-----------------|
| abcd| matched in abcD | ----> should replace first entry because abc is substring of abcd.
所以条目/表应该看起来像
|------|-----------------|
| abcd | matched in abcD |
|------|-----------------|
| match| matched in abcD |
|------|-----------------|
| abc | abc found again |
有什么建议吗?
可能的功能定义
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"])
如果value
存在,则应首先匹配value
的所有新条目,然后检查key
是否key
是其他的子字符串然后更长的字符串应该得到|------|----|
| a | 1 |
|------|----|
| b | 2 |
|------|----|
| ba | 3 |
这个地方。
示例2:
|------|----|
| ab | 1 | ----> should replace first
|------|----|
| b | 2 | ----> should be discarded because already present
|------|----|
| ab | 3 | ----> will be new insertion
如果有新条目
|------|----|
| ab | 1 |
|------|----|
| b | 2 |
|------|----|
| ba | 3 |
|------|----|
| ab | 3 |
所以结果条目/表应该是:
if(!condition){
switch(const) {
case one : value = x; break;
case two : value = y; break;
}
} else {
switch(const) {
case one : value = p; break;
case two : value = q; break;
}
}