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

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

本站已经建立2583天!

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