竞赛 - 什么是(最佳)解决方案? [英] CONTEST - What is the (best) solution?

查看:72
本文介绍了竞赛 - 什么是(最佳)解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文件中可以有几个这样的词典

{Key11:Value11

Key12:Value12

Key13:Value13,

....

....

Key1n:Value1n}

{Key21:Value21

Key22:Value22

Key23:Value23,

....

....

Key2n:Value2n}

{Key31:Value31

Key32:Value32

Key33:Value33,

.. ..

....

Key3n:Value3n}

.....

... ..

.....

{Keyn1:Valuen1

Keyn2:Valuen2

Keyn3:Value3,

....

....

Keynn:Valuenn}


每一对在字典中由CRLF分隔并在每个字典中

对的数量可以不同。

我只需要读取第一个和最后一个字典。什么是

最佳解决方案?

谢谢

Lad

解决方案

<一个href =mailto:py **** @ hope.cz> py **** @ hope.cz écrit:

在文件中可以有几个这样的词典
(snip)我只需要阅读第一个和最后一个词典。什么是最佳解决方案?




取决于你的定义''最佳解决方案''。


你的词典可以包含词典吗?


如果没有,你可以阅读文件并剪切在第一个'''''和最后一个'''''。

这两个块将是一个可以评估的字典。


*但是*上面的例子并没有在所有

对之间显示'','但只有一些。这会让你感到高兴(因为你甚至不能用'',''替换''\\'n'')。然后你需要解析两个块

并更正.....

问候,

模糊
< a rel =nofollowhref =http://www.voidspace.org.uk/python/index.shtmltarget =_ blank> http://www.voidspace.org.uk/python/index.shtml




Fuzzyman写道:

你的词典可以包含词典吗?

如果没有,你可以阅读文件,并在第一个''''和最后的
''{''切断。这两个块将是一个可以评估的单个字典。

*但是*上面的例子并没有在所有
对之间显示'',''。但只有一些。这会让你感到沮丧(因为你
甚至不能用''代替''\\'n'','')。然后你需要解析两个块并正确.....
问候,



模糊,
词典不能包含字典。

我重新检查了,我只需要最后一本字典。

我知道怎么能这样做吗?

谢谢

Lad。


In a file there can be several dictionaries like this
{Key11: Value11
Key12: Value12
Key13: Value13,
....
....
Key1n:Value1n}
{Key21: Value21
Key22: Value22
Key23: Value23,
....
....
Key2n:Value2n}
{Key31: Value31
Key32: Value32
Key33: Value33,
....
....
Key3n:Value3n}
.....
.....
.....
{Keyn1: Valuen1
Keyn2: Valuen2
Keyn3: Value3,
....
....
Keynn:Valuenn}

Each pair in a dictionary is separated by CRLF and in each dictionary
numbers of pairs can be different.
I need to read only the the first and the last dictionaries.What is a
best solution?
Thanks
Lad

解决方案

py****@hope.cz a écrit :

In a file there can be several dictionaries like this (snip) I need to read only the the first and the last dictionaries.What is a
best solution?



Depends on your definition of ''best solution''.


Can your dictionaries contain dictionaries ?

If not you can read the file and cut at the first ''}'' and the last ''{''.
The two chunks will then be a single dictionary which can be eval''d.

*However* your example above does not show '','' between all of the
pairs... but only some. This will bugger you royally (because you can''t
even replace ''\n'' with '',''). You''d then need to parse the two chunks
and correct.....
Regards,
Fuzzy
http://www.voidspace.org.uk/python/index.shtml



Fuzzyman wrote:

Can your dictionaries contain dictionaries ?

If not you can read the file and cut at the first ''}'' and the last ''{''. The two chunks will then be a single dictionary which can be eval''d.

*However* your example above does not show '','' between all of the
pairs... but only some. This will bugger you royally (because you can''t even replace ''\n'' with '',''). You''d then need to parse the two chunks
and correct.....
Regards,


Hi Fuzzy,
dictionaries can NOT contain dictionaries.
I re-checked and I would need only the last dictionary.
Any idea how I could do that?
Thanks
Lad.


这篇关于竞赛 - 什么是(最佳)解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆