给定词典:
dictMnths = dict((v,k) for k,v in enumerate(calendar.month_abbr))
我希望使用dictMonths
类似于下面的元组('Jan','Feb')
:
'aaFeb'.endswith(('Jan','Feb'))
# True
keys()
'aaFeb'.endswith(dictMnths.keys())
# TypeError: endswith first arg must be str or a tuple of str, not dict_keys
str()
'aaFeb'.endswith(str(dictMnths.keys()))
# False
这不是期望的答案,因为dictMonths
包含Feb
使用
tuple()
应该会有所帮助输出:
注意:我使用
filter(None, dictMnths.keys())
只是删除空元素相关问题 更多 >
编程相关推荐