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

本站现有博文333篇,共被浏览922604

本站已经建立2628天!

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