064字典集合作业

1.

d={'001':'88','002':'84','003':'89','004':'86','005':'82'}
>>> d['002']
'84'
>>> d.get('003')

SyntaxError: unexpected indent
>>> d.get('003')
'89'
>>> d.pop('003')
'89'
>>> d.get('003')
>>> print(d.get('003'))
None
>>> d
{'001': '88', '002': '84', '004': '86', '005': '82'}
>>> d.keys()
dict_keys(['001', '002', '004', '005'])
>>> d.values()
dict_values(['88', '84', '86', '82'])
>>> d.items()
dict_items([('001', '88'), ('002', '84'), ('004', '86'), ('005', '82')])

2.

s=list('2347555544')
tu=tuple('9876687879')
print(ls)
print(tu)
dc=dict(zip(ls,tu))
print(dc)
print('ls遍历\n') 
for i in ls:
print(i)
print('tu遍历\n') 
for i in tu:
print(i)

print('dict遍历\n') 
for i in dc:
print(i,dc[i])

列表里面的数据是可变的,可增删改插。但是元组里面的数据是不可变的,只可增,不可删改,字典的查找与插入速度快,但是占用内存,浪费多,不能排序;集合不能重复,不存储values,创建集合需要提供一个列表作为输入集合。

3.s='''every night in my dreams 
i see you, i feel you,
that is how i know you go on 
far across the distance 
and spaces between us 
you have come to show you go on 
near, far, wherever you are 
i believe that the heart does go on 
once more you open the door 
and you're here in my heart 
and my heart will go on and on 
love can touch us one time 
and last for a lifetime 
and never let go till we're one 
love was when i loved you 
one true time i hold to 
in my life we'll always go on 
near, far, wherever you are 
i believe that the heart does go on 
once more you open the door 
and you're here in my heart 
and my heart will go on and on 
there is some love that will not go away 
you're here, there's nothing i fear,
and i know that my heart will go on 
we'll stay forever this way 
you are safe in my heart 
and my heart will go on and on
'''

s=s.lower()
s=s.replace('\n',' ')
word=s.split(' ')
dic={}
keys=set(word)
for i in keys:
dic[i]=word.count(i)
print(dic)

转载于:https://www.cnblogs.com/-064/p/7573343.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值