この記事はPythonの辞書操作(6種類)をまとめたもので、ある程度の参考価値はありますので、困っている方は参考にしていただければ幸いです。
辞書は、一連の「キーと値」のペアである {} で表されます。キーを使用して、対応する値にアクセスできます。この値には、数値、文字列、 Python オブジェクト。キーと値はコロン
で区切られ、キーと値のペアはカンマで区切られます。例: A={'color': 'red', 'points': 10}
1. 辞書の値
にアクセスするには、辞書名と辞書のキーを指定するだけです。 。
A={'a':7,'b':'happy'} print(A['a']) >>>7
2. キーと値のペアの追加
A={'a':7,'b':'happy'} A['c']=8 print(A) >>>{'a': 7, 'b': 'happy', 'c': 8}
3. キー値の変更
A={'a':7,'b':'happy'} A['a']=8 print(A) >>>{'a': 8, 'b': 'happy'}
4. キーと値のペアの削除
A={'a': 7, 'b': 'happy', 'c': 8} del A['c'] print(A) >>>A={'a':7,'b':'happy'}
5. トラバース辞書
x と y は、読みやすくするために実際の状況に応じて変更できます。
book={ 'number':'0', 'name':'从入门到放弃', 'author':'XXX', } for x, y in book.items(): #1、同时取键值对 print(x+':'+y) for x in book.keys(): #2、只取键 print(x) for x in book.values(): #3、只取值 print(x)
値のみを取得する場合、辞書内のすべての値が抽出され、重複する値は考慮されません。重複しない値を含むリストが必要な場合は、 set() を使用できます。これにより、重複した項目が自動的に削除されます。
for x in set(book.values()): print(x)
6. ネスト
状況に応じて、リストと辞書を辞書内に入れ子にすることができます。
以上がPythonでの辞書操作まとめ(6種類)の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

Pythonlistscanstoreanydatatype,arraymodulearraysstoreonetype,andNumPyarraysarefornumericalcomputations.1)Listsareversatilebutlessmemory-efficient.2)Arraymodulearraysarememory-efficientforhomogeneousdata.3)NumPyarraysareoptimizedforperformanceinscient

heouttemptemptostoreavure ofthewrongdatatypeinapythonarray、yure counteractypeerror.thisduetothearraymodule'sstricttypeeencultionyを使用します

PythonListSarePartOfThestAndardarenot.liestareBuilting-in、versatile、forStoringCollectionsのpythonlistarepart。

theScriptisrunningwithwrongthonversionduetorectRectDefaultEntertersettings.tofixthis:1)CheckthedededefaultHaulthonsionsingpython - versionorpython3-- version.2)usevirtualenvironmentsbycreatingonewiththon3.9-mvenvmyenv、andverixe

PythonArraysSupportVariousoperations:1)SlicingExtractsSubsets、2)Appending/ExtendingAdddesements、3)inSertingSelementSatspecificpositions、4)remvingingDeletesements、5)sorting/verversingsorder、and6)listenionsionsionsionsionscreatenewlistsebasedexistin

numpyarraysAressertialentionsionceivationsefirication-efficientnumericalcomputations andDatamanipulation.theyarecrucialindatascience、mashineelearning、物理学、エンジニアリング、および促進可能性への適用性、scaledatiencyを効率的に、forexample、infinancialanalyyy

UseanArray.ArrayOverAlistinPythonは、Performance-criticalCode.1)homogeneousdata:araysavememorywithpedelements.2)Performance-criticalcode:Araysofterbetterbetterfornumerumerumericaleperations.3)interf

いいえ、notallistoperationSaresuptedbyarrays、andviceversa.1)arraysdonotsupportdynamicoperationslikeappendorintorintorinsertizizing、whosimpactsporformance.2)リスト


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

Safe Exam Browser
Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

WebStorm Mac版
便利なJavaScript開発ツール

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

ホットトピック









