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

本站现有博文321篇,共被浏览783127

本站已经建立2476天!

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