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

本站现有博文332篇,共被浏览890646

本站已经建立2592天!

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