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




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值