本文介绍了Rant(Re:x * x,如果x> 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

On Sun,2008年7月27日05:24:36 -0700(PDT),alex23< wu ***** @ gmail.comwrote:



我看过PERL说/座右铭/吹嘘,有不止一种方法可以做到这一点

不止一次在这个群体上嘲笑那么这是什么原因让

这种额外的方式将if else语句放在一行上?是和和

或结构产生相同的效果不支持这种用途?


虽然我在高高在上,但我想提出列表连接。我最近需要
来连接5个列表,这对我来说并不是一个特别好的b
罕见的要求。我的第一次尝试是一个简单的循环

扩展一个空列表。这很好,但看起来像一个可怕的笨重的

解决方案。然后我尝试使用减少的各种公式。 ,落条犯规

的=抓住一次。现在我不是一个专业的程序员,所以

可能有充分的理由让一个对象在一个

程序中有多个名字,但这听起来像一个食谱为了灾难我。回到

列表连接,我终于找到了itertools.chain命令,它是最紧凑和最快的

(或者是一个微不足道的第二快,我可以' '$

记住哪个)。一路上,我必须尝试/使用了六种方法,

....这让我回到了我最初的PERL评论。在Python中也有不止一种方式




DaveM

解决方案



我看过PERL说/座右铭/吹嘘,有不止一种方法可以做到这一点

不止一次在这个群体上嘲笑那么这是什么原因让

这种额外的方式将if else语句放在一行上?是和和

或构造产生相同的效果不支持此用途?



你显然不知道有关误用或

以及此用途的缺陷。


试试这个:



1



2



2




你能告诉我们你的意思是一个对象的几个名字吗?你的意思是

这个?


a =范围(10)

b = a


id(a)== id(b)

?传递引用而不是值是一个非常重要的概念

多种语言,如果没有它,你最终会在大多数情况下复制。



任何非平凡的任务都有该属性。我不知道perl有足够的per / b
一个示例准备好了,表示python只有一种方式来做
做,而perl有几种。


但我*确实*知道蟒蛇禅字面上没有结果。

Diez




任何非平凡的任务都有该属性。我不知道perl有足够的per / b
一个示例准备好了,表示python只有一种方式来做
做,而perl有几种。


但我*确实*知道从字面上理解python zen是徒劳的。



我认为应该采取更多的字面意义而不是错误的减少

应该只有一种方式。人们往往会忘记明显的和

优选所有的时间。


Ciao,

Marc''BlackJack''Rintsch






我看过PERL的说法/座右铭/夸耀,有不止一种方法可以做到这一点

不止一次嘲笑这个群体所以这是什么原因导致

这种在一行上放置if else语句的额外方法?是和和

或产生相同效果的结构不支持此用途?



和和或构造,它相当于三元运算符

非常复杂,看起来不像条件计算:

(C和[A]或[b])[0]

这是低效的,几乎不可读,这使得高度有用的三元运算符值得一个语法结构。

[A],[ b]和[0]部分在一般情况下绝对必要

其中A可以具有Python认为等于False的值。

如果你知道A将永远不会相当于False然后你可以使用这个:

C和A或B


加里赫伦


On Sun, 27 Jul 2008 05:24:36 -0700 (PDT), alex23 <wu*****@gmail.comwrote:

I''ve seen the PERL saying/motto/boast, "There''s more than one way to do it"
derided on more than one occasion on this group so what''s the reason for
this additional way to put an if else statement on one line? Are "and" and
"or" constructions to produce the same effect not supported for this use?

And while I''m on my high horse, I''d like to bring up list concatenations. I
recently needed to concatenate 5 lists, which doesn''t sound a particularly
rare requirement to me. My first attempt was a straightforward loop
extending an empty list. That worked fine but looked like an awful bulky
solution. Afterwards I tried various formulae using "reduce" , falling foul
of the "=" catch on one occasion. Now I''m not a professional programmer, so
there may be good reasons for a single object to have multiple names in a
program, but it sounds like a recipe for disaster to me. Getting back to the
list concatenation, I finally found the itertools.chain command which is the
most compact and fastest (or second fastest by a trivial amount, I can''t
remember which). Along the way, I must have tried/used half a dozen methods,
....which brings me back my initial PERL comment. There''s more than one way
to do it in Python, too.

DaveM

解决方案


I''ve seen the PERL saying/motto/boast, "There''s more than one way to do it"
derided on more than one occasion on this group so what''s the reason for
this additional way to put an if else statement on one line? Are "and" and
"or" constructions to produce the same effect not supported for this use?

You obviously aren''t aware of the pitfalls regarding the mis-use of or
and and for this usage.

Try this:

1

2

2



Can you tell us what you mean by "several names of one object"? You mean
this?

a = range(10)
b = a

id(a) == id(b)
? Passing references instead of values is an extremely important concept
of many languages, without it you would end up copying most of the time.

Any non-trivial task has that property. I don''t know enough perl to have
an example ready that shows something that python has only one way of
doing and perl has several.

But I *do* know that taking the python zen literally is fruitless.
Diez



Any non-trivial task has that property. I don''t know enough perl to have
an example ready that shows something that python has only one way of
doing and perl has several.

But I *do* know that taking the python zen literally is fruitless.

I think it should be taken more literally than the wrong reduction to
"there should be only one way". People tend to forget "obvious" and
"preferably" all the time.

Ciao,
Marc ''BlackJack'' Rintsch





I''ve seen the PERL saying/motto/boast, "There''s more than one way to do it"
derided on more than one occasion on this group so what''s the reason for
this additional way to put an if else statement on one line? Are "and" and
"or" constructions to produce the same effect not supported for this use?

The "and" and "or" construct which is equivalent to the ternary operator
is quite convoluted and looks nothing like a conditional computation:
(C and [A] or [b])[0]
This is inefficient, and nearly unreadable, which makes the highly
useful ternary operator worthy of a syntactical construct.
The [A], [b] and [0] parts are absolutely necessary in the general case
where A can have values that Python would consider equivalent to False.
If you know A will never be equivalent to False then you can use just this:
C and A or B

Gary Herron


这篇关于Rant(Re:x * x,如果x> 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 20:40