Python Data Structures (数据结构)

#Python Data Structures
#working with lists
words = "the quick brown for jumps over the lazy dog".split()
print(words)
info = [[w.upper(),w.lower(),len(w)] for w in words]
for data in  info:
    print (data)


#Dictionaries
students = {'name':'Alex' ,'age' : 16 ,'grade':'sixth'}
print('name ',students['name'])

# Organizing Data using Diectionaries

d = {'three' : 3 , 'one':1,'two':2}
x = dict(six =6 ,four =4 ,five =5)
t = dict(one =1 ,tow =2 ,three = 3,**x)
print t

print 'three' in t

print 'r' in t
for k in t : print  k  # print the key
for k,v in t.items() : print (k,v )


print t.get('five1','data not found')

print x.pop('five')
print x

# updating Dictionary Elements

student = {'name':'lisi'}
print  student['name']
student['name']='zsan'

print  student['name']

#Deleting Dictionary elements
student = {'name':'lisi','comments':'some comments for tesint del'}

del student['comments']
print  student['comments']

student.clear()
del student




你可能感兴趣的:(Python)