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

本站现有博文311篇,共被浏览740699

本站已经建立2378天!

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