本文整理匯總了Python中builtins.sorted方法的典型用法代碼示例。如果您正苦於以下問題:Python builtins.sorted方法的具體用法?Python builtins.sorted怎麽用?Python builtins.sorted使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類builtins
的用法示例。
在下文中一共展示了builtins.sorted方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testEnvironment
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import sorted [as 別名]
def testEnvironment(self):
from amplpy import Environment, AMPL
env1 = Environment()
env2 = Environment(os.curdir)
self.assertEqual(env2.getBinDir(), os.curdir)
env1.setBinDir(env2.getBinDir())
self.assertEqual(env1.getBinDir(), env1.getBinDir())
self.assertEqual(len(dict(env1)), len(list(env1)))
self.assertEqual(list(sorted(dict(env1).items())), list(sorted(env1)))
env1['MyEnvVar'] = 'TEST'
self.assertEqual(env1['MyEnvVar'], 'TEST')
self.assertEqual(env2['MyEnvVar'], None)
d = dict(env1)
self.assertEqual(d['MyEnvVar'], 'TEST')
ampl = AMPL(Environment())
ampl.close()
示例2: sorted
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import sorted [as 別名]
def sorted(iterable, *args):
'''Replacement for the built-in
:func:`sorted() <python:sorted>` function.'''
return builtins.sorted(iterable, *args)
示例3: sorted
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import sorted [as 別名]
def sorted(iterable, cmp=None, key=None, reverse=False):
if key is not None:
result = [(key(x), x) for x in iterable]
else:
result = iterable[:]
if cmp is None:
# Pre-2.3 Python does not support list.sort(None).
result.sort()
else:
result.sort(cmp)
if key is not None:
result = [t1 for t0,t1 in result]
if reverse:
result.reverse()
return result