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

本站现有博文328篇,共被浏览850952

本站已经建立2557天!

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