我有一个格式为 {'string-value-keys':[list-values]} 的字典。对于特定的键值,我想将该值作为字符串检索。这是示例:
>>> simpleDict= {'DDL_TABLE1':['create table bla', ' columns bla bla'], 'DML_TABLE1': ['insert into bla', ' values bla']}
>>> simpleDict
{'DDL_TABLE1': ['create table bla', ' columns bla bla'], 'DML_TABLE1': ['insert into bla', ' values bla']}
>>> sqlQry= " ".join(value for key, value in simpleDict.items() if 'DDL' in key)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected string, list found
>>> sqlQry= " ".join(value for key, value in simpleDict.items() if 'DDL' in key)
当 value 是字符串值列表时,我无法理解为什么会出现此错误。