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

本站现有博文324篇,共被浏览807367

本站已经建立2508天!

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