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

本站现有博文321篇,共被浏览764929

本站已经建立2443天!

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