English 中文(简体)
报酬
原标题:Null and Sorting

With NaN, it is possible to get a list that will not properly sort:

--> NaN = float( nan )
--> spam = [1, 2, NaN, 3, NaN, 4, 5, 7, NaN]
--> sorted(spam)
[1, 2, nan, 3, nan, 4, 5, 7, nan]

构造一个<代码>Null的物体,如<代码>NaN,则其实际价值不为人知。 www.un.org/spanish/ga/president

从纯净角度看,如果不知道,那么比较结果也是不了解的,因为实际价值可能更大,减少,或与所比较的价值相同。

从实际的角度来看,一份遍布各地的Nuss清单是背后的痛苦。

因此,我非常倾向于实施比较,使Null物体少于其他物体,因此它们将永远合在一起。

当然,我总是能够处理该问题,迫使用户执行习惯的关键。

任何思想/信仰/意识形态?

最佳回答

如果<代码>Null的物体实施比较行为,其他方法(例如索引编制)就会变得更加复杂。 考虑:

target = table.sql( select * where sales < 1000.00 )

如果对“Null的数值作比较和比较,则所有其他物体在上的上,在无销售的情况下,可以有行踪(这不是目标)。

因此,我认为实际性和纯度都出现在同一个方面: 彩票比较结果不明。 用户如果获得Null数值,将不得不决定什么。

问题回答

<代码>Na通常被定义为与任何东西不相近。 任何涉及<代码>NaN的计算,均应退还<代码>NaN。

事实上:

>>> print float( nan ) == float( nan )
False

Yes: NaN is not even the same as itself. There are good reasons to have it this way, although it indeed is counter-intuitive. The prime reason probably is that - in contrast to all other numbers - there is no unique way of sorting them ascending. Should the come first, last, at the end? before or after infinity? Floating point numbers have a couple of odd things. But at least there is no doubt about -infty < -123 < -0 <= +0 < 123 < +infty.

它不是“数量”,因此,它如何比数量大、小或平等?

Of course you can define a custom compare function that has a well-defined sorting behavior for NaN values:

def s(x, y):
  import math
  if math.isnan(x): return 1
  return cmp(x, y)

说明使用<代码>的Im。 这项职能具有明确的属性:首先,它对所有数字进行分类,然后是任何<条码>。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签