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

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

本站已经建立2538天!

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