菜鸟提问,关于字符匹配和提取数值

xxhwang 2013-02-18 11:13:49
请教 如何提取数值,查找相同的intersection_sum?

Suppose Bugs (p1) and Elmer (p2) have rated the following flavours:
“Bugs” : {“lemon”:6, “maple walnut”:2, “chocolate”: 5, “bubble gum”: 4}
“Elmer” : {“mocha”: 4, “lemon”: 5, “bubble gum”: 7}

程序框架:
p1_sum = 6+2+5+4 = 17 (the sum of Bugs's ratings)
p2_sum = 4+5+7 = 16 (the sum of Elmer's ratings)
intersection_sum = min(6,5) + min(4,7) = 5+4 = 9(since they both rated lemon and bubble
gum)

similarity = min (9/17, 9/16)= 9/17 (remembering to make sure these are not both
evaluated to 0 due to integer division)
...全文
95 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
夏之冰雪 2013-02-18
  • 打赏
  • 举报
回复
“(\s*)”:(\d+), 1和2分别是key和value
CrySleeper 2013-02-18
  • 打赏
  • 举报
回复
intersection_sum=0 for key in bug.keys(): if key in elmer: intersection_sum=min(bug[key],elmer[key])+intersection_sum

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧