


Summary of several methods for traversing python dictionary
The editor below will bring you a summary of several methods of traversing python dictionaries (recommended). The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.
is as follows:
aDict = {'key1':'value1', 'key2':'value2', 'key3':'value3'} print '-----------dict-------------' for d in aDict: print "%s:%s" %(d, aDict[d]) print '-----------item-------------' for (k,v) in aDict.items(): print '%s:%s' %(k, v) #效率最高 print '------------iteritems---------' for k,v in aDict.iteritems(): print '%s:%s' % (k, v) #最笨的方法 print '---------iterkeys---------------' for k in aDict.iterkeys(): print '%s:%s' % (k, aDict[k]) print '------------iterkeys, itervalues----------' for k,v in zip(aDict.iterkeys(), aDict.itervalues()): print '%s:%s' % (k, v)
Running results:
<pre name="code" class="python">-----------dict------------- key3:value3 key2:value2 key1:value1 -----------item------------- key3:value3 key2:value2 key1:value1 ------------iteritems--------- key3:value3 key2:value2 key1:value1 ---------iterkeys--------------- key3:value3 key2:value2 key1:value1 ------------iterkeys, itervalues---------- key3:value3 key2:value2 key1:value1
The above article traverses several python dictionaries The method summary (recommendation) is all the content shared by the editor. I hope it can give you a reference, and I also hope you will support the PHP Chinese website.
For more summary of several methods of traversing python dictionary and related articles, please pay attention to the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...

Using python in Linux terminal...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...
