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

本站现有博文327篇,共被浏览828341

本站已经建立2534天!

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