EADST

Python: Sort the Dictionary Based on Key or Value

Python: Sort the Dictionary Based on Key or Value

a = { "b": 5, "c": 2,"a": 4, "d": 1}
test_1=sorted(a.items(),key=lambda x:x[0]) # sort the dictionary based on key
print(test_1) # [('a', 4), ('b', 5), ('c', 2), ('d', 1)]
test_2=sorted(a.items(),key=lambda x:x[1]) # sort the dictionary based on value
print(test_2) # [('d', 1), ('c', 2), ('a', 4), ('b', 5)]

相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
Firewall Base64 Permission JSON Qwen2.5 Bipartite printf Google ResNet-50 Streamlit NameSilo SPIE PDB Datetime Conda Tiktoken Tracking Linux Image2Text Interview Anaconda ChatGPT Breakpoint Agent EXCEL TensorFlow SVR AI Distillation Land Django 阿里云 继承 搞笑 WebCrawler Ubuntu UNIX uwsgi Numpy Video 论文速读 Website Paddle Nginx Translation Use Rebuttal Color 第一性原理 Zip v2ray Quantize VSCode mmap git Pickle 递归学习法 多进程 Disk CAM Diagram tar Sklearn Input Proxy Qwen2 Heatmap Password CUDA FlashAttention Jetson 音频 CSV XGBoost Claude OpenCV FP64 NLTK Magnet FP32 Quantization NLP Docker Web Mixtral UI VPN Domain FP8 C++ Food ModelScope llama.cpp Tensor Review BeautifulSoup 证件照 FP16 PDF COCO ONNX Vmess icon Windows PyCharm IndexTTS2 CTC DeepSeek Git logger Qwen 顶会 Clash 腾讯云 Bert Github torchinfo Python transformers Llama Augmentation 报税 Statistics Animate Shortcut Ptyhon BTC SQLite CV Excel MD5 Knowledge LLAMA Algorithm OCR Paper Pandas 飞书 Jupyter Safetensors Math Data scipy News FastAPI GGML Hotel Crawler Transformers 图标 算法题 BF16 关于博主 ms-swift Markdown 财报 多线程 公式 TensorRT YOLO v0.dev API HuggingFace Vim PIP 强化学习 LaTeX Bitcoin Plate SQL CLAP 签证 Gemma Hungarian uWSGI Bin Plotly SAM Random diffusers TSV Card Cloudreve Miniforge git-lfs Attention 图形思考法 tqdm Freesound GPTQ 域名 GoogLeNet GPT4 LoRA GIT Logo Pillow CEIR Michelin 版权 Dataset DeepStream Template XML PyTorch CC 云服务器 TTS 净利润 VGG-16 InvalidArgumentError hf Pytorch 论文 HaggingFace QWEN WAN Baidu LLM OpenAI RAR RGB LeetCode Search Hilton
站点统计

本站现有博文329篇,共被浏览860347

本站已经建立2568天!

热门文章
文章归档
回到顶部