嗨,制作一个文件,通过一个txt文件排序,并选择名称:和前3个统计数据,并存储在一个dict,然后做同样的下一个名称+3统计如果dict是不聪明的存储在一个列表中他们也会工作,我想。你知道吗
player a 34 45 56 player b 38 93 75 playerc 39 29 18 playerd 38 98
我试过player = re.findall(r"[-+]?\d*\.\d+|\d+", player_string)
但它只给我的球员评分,我想我需要使用某种dict来存储所有不同的球员。你知道吗
如果这很复杂,你不必为我做所有的事情,只要给我指出正确的方向。 非常感谢。 我用的是py2.6
我想你需要的是:
注意,你写的“playerc”和“playerd”没有空格,这两个将不会被找到。你知道吗
我想这可能会给你一些你想要的东西,尽管不使用正则表达式:
这将给出一个类似于
['', 'a 34 45 56', ...]
的列表,其中每个元素都应该包含不同播放器的信息。接下来,我们将这些元素拆分为一个字典,其中玩家名称是键,统计数据是值:你可以修改它,只获得前两个或三个属性,或者改变属性的存储方式。您给出的列表上的结果
my_dict.items()
是:我想你需要的是:
在最后一个玩家“playerd”之后,你只有2个数字,而不是regex期望的3个。你知道吗
输出:
相关问题 更多 >
编程相关推荐