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

本站现有博文323篇,共被浏览795341

本站已经建立2493天!

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