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

本站现有博文319篇,共被浏览753517

本站已经建立2411天!

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