我有使用javascript通过POST获得的dict数据。dict数据保存在变量“commands”中,commands中的数据如下所示:
{flightplantext': 'TAKEOFF\r\nUP 80\r\nDOWN 80\r\nLAND'}
我想用python以以下格式将此数据存储在新的dict/列表中:
{'takeoff', 'up_80', 'down_80', 'land'}
基本上,我希望将每个命令按\r\n
部分拆分,使其小写,如果命令和数字之间有空格,则使用下划线
我对Python非常陌生,非常感谢。提前非常感谢
如果您可以从javascript中获取的数据中提取字符串
因此
data
将是如下所述的字符串输出将是
使用带有列表理解的
re.findall
生成字典,我们可以尝试:假设您的commands变量是
dict
,这就是您要查找的:相关问题 更多 >
编程相关推荐