我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用__builtin__.sorted()。
def fullfile(*args): return os.path.join(*args) # implemented in "scripts/set/intersect.m" #def intersect(a,b,nargout=1): # if nargout == 1: # c = sorted(set(a) & set(b)) # if isinstance(a,str): # return "".join(c) # elif isinstance(a,list): # return c # else: # # FIXME: the result is a column vector if # # both args are column vectors; otherwise row vector # return np.array(c) # raise NotImplementedError #
def get_vocab(data): vocab = set() for analogy in data: vocab.update(analogy) vocab = sorted(vocab) return dict([(a, i) for i, a in enumerate(vocab)]), vocab
def flazy(f, *a, **k): sortedtuple, state = fcompose(__builtin__.sorted, __builtin__.tuple), {} def lazy(*ap, **kp): A, K = a+ap, sortedtuple(k.items() + kp.items()) return state[(A,K)] if (A,K) in state else state.setdefault((A,K), f(*A, **__builtin__.dict(k.items()+kp.items()))) return lazy
def reversed(data): if not isinstance(data, list): data = list(data) reversed_data = [] for index in xrange(len(data)-1, -1, -1): reversed_data.append(data[index]) return reversed_data # --- sorted() from Python 2.4 ---
def sorted(data): sorted_data = copy.copy(data) sorted_data.sort() return sorted