Results of 1 - 10 of about 35 for sorted (0.006 sec.)
- ソートのテクニック 16963
- ソートのテクニック Author : Andrew Dalke and Raymond Hettinger Python のリストにはリストをインプレースに変更する、組み込みメソッド list.sort() があります。他にもイテラブルからソートしたリストを作成する組み込み関数 sorted() があります。 この
...ドキュメントでは Python を使った様々なソートのテクニックを探索します。 ソートの基本 単純な昇順のソートはとても簡単です: sorted() 関数を呼ぶだけです。そうすれば、新たにソートされたリストが返されます: >>> sorted ([ 5 , 2 , 3 , 1 , 4 ]) [1, 2, 3, 4, 5]...list.sort() メソッドを呼びだしても同じことができます。この方法はリストをインプレースに変更します (そして sorted との混乱を避けるため None を返します)。多くの場合、こちらの方法は sorted() と比べると不便です - ただし、元々のリストが不要...4 ] >>> a . sort () >>> a [1, 2, 3, 4, 5] 違いは他にもあります、 list.sort() メソッドはリストにのみ定義されています。一方 sorted() 関数は任意のイテラブルを受け付けます。 >>> sorted ({ 1 : 'D' , 2 : 'B' , 3 : 'B' , 4 : 'E' , 5 : 'A' }) [1, 2, 3, 4, 5]... - https://man.mtool.work/python/3.14/howto/sorting.html
- heapq --- ヒープキューアルゴリズム 9038
- heapq --- ヒープキューアルゴリズム ソースコード: Lib/heapq.py このモジュールではヒープキューアルゴリズムの一実装を提供しています。優先度キューアルゴリズムとしても知られています。 最小ヒープは、各親ノードの値がそのどの子ノードの値以下でもある
...にします (たとえば、複数のログファイルの時刻の入ったエントリーをマージします)。ソートされた値にわたる iterator を返します。 sorted(itertools.chain(*iterables)) と似ていますが、イテレータを返し、一度にはデータをメモリに読み込まず、それぞれの入力ストリーム...ルト値は None です (要素を直接比較します)。 reverse は真偽値です。 True の場合は比較の向きを逆にして入力要素をマージします。 sorted(itertools.chain(*iterables), reverse=True) と同様の動作にするには、すべての入力イテラブルをあらかじめ降順にソートしておく必...引数を一つとる、 iterable のそれぞれの要素から比較キーを生成する関数を指定します(例 key=str.lower )。以下のコードと同等です: sorted(iterable, key=key, reverse=True)[:n] heapq. nsmallest ( n , iterable , key = None ) iterable で定義されるデータセットのうち... - https://man.mtool.work/python/3.14/library/heapq.html
- 5. データ構造 8720
- 5. データ構造 この章では、すでに学んだことについてより詳しく説明するとともに、いくつか新しいことを追加します。 5.1. リスト型についてもう少し list 型には、他にもいくつかメソッドがあります。リストオブジェクトのすべてのメソッドを以下に示します
...プレース演算 (in place、元のデータを演算結果で置き換えるやりかた) でソートします。引数はソート方法のカスタマイズに使えます。 sorted() の説明を参照してください。 list. reverse ( ) リストの要素を、インプレース演算で逆順にします。 list. copy ( ) リストの浅い...ると、辞書で使われている全てのキーからなるリストをキーが挿入された順番で返します (ソートされたリストが欲しい場合は、代わりに sorted(d) を使ってください)。ある単一のキーが辞書にあるかどうか調べるには、 in キーワードを使います。 以下に、辞書を使った簡単な例...>>> tel [ 'irv' ] = 4127 >>> tel {'jack': 4098, 'guido': 4127, 'irv': 4127} >>> list ( tel ) ['jack', 'guido', 'irv'] >>> sorted ( tel ) ['guido', 'irv', 'jack'] >>> 'guido' in tel True >>> 'jack' not in tel False dict() コンストラクタは、キーと値のペ... - https://man.mtool.work/python/3.14/tutorial/datastructures.html
- What's New in Python 2.4 8242
- What's New in Python 2.4 著者 : A.M. Kuchling この文書は 2005 年 3 月 30 日にリリースされた Python 2.4.1 の新機能について解説します。 Python 2.4 は、真ん中サイズ、のリリースです。急進的だった Python 2.2 ほどには多くの変更をしていませんが、保
...すが同年齢の人物は名前順です。 ( sort() への変更はすべて Raymond Hettinger によるものです。) 新たに追加されたビルトイン関数 sorted(iterable) はインプレイスなメソッド list.sort() と似た振る舞いをしますが、式内で使えます。違いは: 入力には任意のイテラブルを...ます; そして 式として新しいソート済みコピーを返します。 >>> L = [ 9 , 7 , 8 , 3 , 2 , 4 , 1 , 6 , 5 ] >>> [ 10 + i for i in sorted ( L )] # リスト内包表記でも使用可能 [11, 12, 13, 14, 15, 16, 17, 18, 19] >>> L # 元のリストは変更されない [9,7,8,3,2,4,1,6...,5] >>> sorted ( 'Monty Python' ) # 任意のイテラブルを入力にできる [' ', 'M', 'P', 'h', 'n', 'n', 'o', 'o', 't', 't', 'y', 'y'] >>> # 辞書... - https://man.mtool.work/python/3.14/whatsnew/2.4.html
- collections --- コンテナデータ型 8163
- collections --- コンテナデータ型 ソースコード: Lib/collections/__init__.py このモジュールは、汎用の Python 組み込みコンテナ dict , list , set , および tuple に代わる、特殊なコンテナデータ型を実装しています。 namedtuple() 名前付きフィールドを
...す。ある要素のカウントが 1 未満なら、 elements() はそれを無視します。 >>> c = Counter ( a = 4 , b = 2 , c = 0 , d =- 2 ) >>> sorted ( c . elements ()) ['a', 'a', 'a', 'a', 'b', 'b'] most_common ( n = None ) 出現回数が多い順に n 個の要素とそれぞれのカウン..., 3 ), ( 'blue' , 4 ), ( 'red' , 1 )] >>> d = defaultdict ( list ) >>> for k , v in s : ... d [ k ] . append ( v ) ... >>> sorted ( d . items ()) [('blue', [2, 4]), ('red', [1]), ('yellow', [1, 3])] それぞれのキーが最初に登場したとき、マッピングにはまだ...使った等価なものよりシンプルで速いです: >>> d = {} >>> for k , v in s : ... d . setdefault ( k , []) . append ( v ) ... >>> sorted ( d . items ()) [('blue', [2, 4]), ('red', [1]), ('yellow', [1, 3])] default_factory を int にすると、 defaultdict を(他の... - https://man.mtool.work/python/3.14/library/collections.html
- random --- 疑似乱数を生成する 8083
- random --- 疑似乱数を生成する ソースコード: Lib/random.py このモジュールでは様々な分布をもつ擬似乱数生成器を実装しています。 整数用に、ある範囲からの一様な選択があります。 シーケンス用には、シーケンスからのランダムな要素の一様な選択、リスト
...0 )) / 10_000 0.4169 >>> # 5 個のサンプルの中央値が中央の 2 つの四分位区間に入る確率 >>> def trial (): ... return 2_500 <= sorted ( choices ( range ( 10_000 ), k = 5 ))[ 2 ] < 7_500 ... >>> sum ( trial () for i in range ( 10_000 )) / 10_000 0.7958 サン...ean from random import choices data = [ 41 , 50 , 29 , 37 , 81 , 30 , 73 , 63 , 20 , 35 , 68 , 22 , 60 , 31 , 95 ] means = sorted ( mean ( choices ( data , k = len ( data ))) for i in range ( 100 )) print ( f 'The sample mean of { mean ( data ) : .1f }...le , r ): "次からランダムに選択: itertools.combinations(iterable, r)" pool = tuple ( iterable ) n = len ( pool ) indices = sorted ( random . sample ( range ( n ), r )) return tuple ( pool [ i ] for i in indices ) def random_combination_with_replacement... - https://man.mtool.work/python/3.14/library/random.html
- The Python Profilers 8004
- The Python Profilers Source code: Lib/profile.py and Lib/pstats.py Introduction to the profilers cProfile and profile provide deterministic profiling of Python programs. A profile is a set of statistics that describes how often and for how
..., meaning that the call was not induced via recursion. The next line: Ordered by: cumulative time indicates the output is sorted by the cumtime values. The column headings include: ncalls for the number of calls. tottime for the total time spent in th...) . print_stats () The strip_dirs() method removed the extraneous path from all the module names. The sort_stats() method sorted all the entries according to the standard module/line/name string that is printed. The print_stats() method printed out al...d, and that sub-sub-list is printed. If you wondered what functions called the above functions, you could now ( p is still sorted according to the last criteria) do: p . print_callers ( .5 , 'init' ) and you would get a list of callers for each of the... - https://man.mtool.work/python/3.14/library/profile.html
- What's New In Python 3.1 7924
- What's New In Python 3.1 著者 : Raymond Hettinger この記事では Python 3.0 と比較した Python 3.1 の新機能を説明します。 Python 3.1 は 2009 年 6 月 27 日にリリースされました。 PEP 372: 順序付き辞書 通常の Python 辞書は、 key/value ペアを不定の
...ていない辞書 >>> d = { 'banana' : 3 , 'apple' : 4 , 'pear' : 1 , 'orange' : 2 } >>> # キーでソートした辞書 >>> OrderedDict ( sorted ( d . items (), key = lambda t : t [ 0 ])) OrderedDict([('apple', 4), ('banana', 3), ('orange', 2), ('pear', 1)]) >>> # 値...でソートした辞書 >>> OrderedDict ( sorted ( d . items (), key = lambda t : t [ 1 ])) OrderedDict([('pear', 1), ('orange', 2), ('banana', 3), ('apple', 4)]) >>> # キ...ー文字列の長さでソートした辞書 >>> OrderedDict ( sorted ( d . items (), key = lambda t : len ( t [ 0 ]))) OrderedDict([('pear', 1), ('apple', 4), ('orange', 2), ('banana', 3)]) こ... - https://man.mtool.work/python/3.14/whatsnew/3.1.html
- 組み込み関数 7844
- 組み込み関数 Python インタプリタには数多くの関数と型が組み込まれており、いつでも利用できます。それらをここにアルファベット順に挙げます。 組み込み関数 A abs() aiter() all() anext() any() ascii() B bin() bool() breakpoint() bytearray() bytes(
...t() O object() oct() open() ord() P pow() print() property() R range() repr() reversed() round() S set() setattr() slice() sorted() staticmethod() str() sum() super() T tuple() type() V vars() Z zip() _ __import__() abs ( number , / ) 数の絶対値を返しま...れていない場合 ValueError が送出されます。 最大の要素が複数あるとき、この関数はそのうち最初に現れたものを返します。これは、 sorted(iterable, key=keyfunc, reverse=True)[0] や heapq.nlargest(1, iterable, key=keyfunc) のような、他のソート安定性を維持するツ...れていない場合 ValueError が送出されます。 最小の要素が複数あるとき、この関数はそのうち最初に現れたものを返します。これは、 sorted(iterable, key=keyfunc)[0] や heapq.nsmallest(1, iterable, key=keyfunc) のような、他のソート安定性を維持するツールと両立しま... - https://man.mtool.work/python/3.14/builtins/functions.html
- operator --- 関数形式の標準演算子 7844
- operator --- 関数形式の標準演算子 ソースコード: Lib/operator.py operator モジュールは、Python の組み込み演算子に対応する効率的な関数を提供します。 例えば、 operator.add(x, y) は式 x+y と同等です。 多くの関数名は、特殊メソッドの名前から二重ア
...。 Added in version 3.11. operator モジュールは、属性や要素の取得を汎用的に行うツールも定義しています。 これらは、 map() 、 sorted() 、 itertools.groupby() など、関数を引数に取る関数に渡す、高速なフィールド取得用の関数を作るのに役立ちます。 operator. at...'pear' , 5 ), ( 'orange' , 1 )] >>> getcount = itemgetter ( 1 ) >>> list ( map ( getcount , inventory )) [3, 2, 5, 1] >>> sorted ( inventory , key = getcount ) [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)] operator. methodcaller ( name , /... - https://man.mtool.work/python/3.14/library/operator.html