所以我正在处理一些文件,其中我会计算某些单词,看看他们分享了各自文档的内容,看看这些内容在不同文档之间的比较情况。
这是我正在做的伪代码:
if(share doc 1 < share doc 2): (share doc 1 / share doc 2)
else: (share doc 2 / share doc 1)
结果打印为0.7821 ......,或类似的东西。
现在,作为一个例子,当我输入:
5+7, 8*3
结果打印到(12,24)
有没有办法用我的if-else语句呢?以下的方式:
[if(share doc 1 < share doc 2): (share doc 1 / share doc 2)
else: (share doc 2 / share doc 1)],
[if(share doc 3 < share doc 4): (share doc 3 / share doc 4)
else: (share doc 3 / share doc 4)], ...
打印:(0.7823,0.5682,...)
我尝试在不同的地方插入括号,但只得到错误&#34;语法错误:无效的语法&#34;它指的是“如果&#39;在开始。
如果您需要更多详细信息,请与我们联系。谢谢!
编辑:为了澄清,我有大约88个文档来执行此操作,这个过程对于每个文档对一次一个地执行非常重复/耗时。我想要的是粘贴所有代码,否则我会反复复制粘贴,放入括号(或者原来的任何内容)并打印所有结果的列表。
编辑2:我得到了它的工作,但发布答案的用户删除了他们的帖子。他建议我改变语法,它看起来像这样:
(share doc 1 / share doc 2) if (share doc 1 < share doc 2) else (share doc 2 / share doc 1)
它创造了奇迹!然而,我将标记作为解决方案的唯一其他答案,即使它不是我使用的方法,所以这篇文章已经解决。
答案 0 :(得分:0)
if(share_doc_1 < share_doc_2):
x = (share_doc_1 / share_doc_2)
else:
x = (share_doc_2 / share_doc_1)
if(share_doc_3 < share_doc_4):
y = (share_doc_3 / share_doc_4)
else:
y = (share_doc_3 / share_doc_4)
print (x,y)