2024-04-29 15:11:12 发布
网友
如何使以下功能与Python 2.7之前的Python版本兼容?
gwfuncs = [reboot, flush_macs, flush_cache, new_gw, revert_gw, send_log] gw_func_dict = {chr(2**i): func for i, func in enumerate(gwfuncs[:8])}
使用:
gw_func_dict = dict((chr(2**i), func) for i, func in enumerate(gwfuncs[:8]))
这是dict()函数,它有一个生成(key, value)对的生成器表达式。
dict()
(key, value)
或者,概括地说,是对形式的听写理解:
{key_expr: value_expr for targets in iterable <additional loops or if expressions>}
始终可以使用以下方法使其与Python<;2.7兼容:
dict((key_expr, value_expr) for targets in iterable <additional loops or if expressions>)
使用:
这是
dict()
函数,它有一个生成(key, value)
对的生成器表达式。或者,概括地说,是对形式的听写理解:
始终可以使用以下方法使其与Python<;2.7兼容:
相关问题 更多 >
编程相关推荐