- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
有没有更简洁或者pythonic的方式来编写 boolean 表达式
a + b == c or a + c == b or b + c == a
我想出了
a + b + c in (2*a, 2*b, 2*c)
但这有点奇怪。
最佳答案
如果我们看一下 Python 之禅,请强调我的:
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
最 Pythonic 的解决方案是最清晰、最简单、最容易解释的解决方案:
a + b == c or a + c == b or b + c == a
更好的是,您甚至不需要了解 Python 即可理解此代码!这很容易。这是毫无保留的最佳解决方案。其他任何东西都是智力手淫。
此外,这也可能是性能最好的解决方案,因为它是所有短路提案中唯一的一个。如果a + b == c
,只进行一次加法和比较。
关于python - 简洁的书写方式(a + b == c 或 a + c == b 或 b + c == a),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32085675/
我正在开发 GPA 计算器,而且我是 C 语言新手。我在 Ubuntu 12 中使用 gvim 编写此代码,并在终端中使用 gcc 进行编译。 这是我到目前为止的代码。我还想包含一种检查方法,以确保用
我正在使用tinymce 编辑网络应用程序中的某些字段。我需要一个带有一些规范的 html 结果(编辑后)。 例如:当我按 Entertinymce 时,创建一个新段落(没关系,我知道可以更改此行为,
我正在尝试在EmguCV(OpenCV C#包装器)图像上绘制多于一行的字符串。但它表明EmguCV无法识别新行“\ r \ n”字符。 如何实现呢?另外,如何获取文本高度,以便可以手动设置下一个字符
我有一个 richTextBox,一个人将在其中阅读患者的医疗记录。 我添加了一个按钮,用于将今天的日期(以 DD/MM/YYYY 格式)添加到 richTextBox 中。当有人需要更新病人的记录时
我是一名优秀的程序员,十分优秀!