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

本站现有博文320篇,共被浏览755666

本站已经建立2418天!

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