第三次

总结列表,元组,字典,集合区别:

 (1) 列表是可变的对象,可进行动态的增加、删除、更新,用[]表示。

 (2) 元组和列表在结构上没有什么区别,唯一的差异在于元组是只读的,不能修改元组用“()”表示。

 (3)字典是存储键值对数据的对象,字典的元素都是无序的,且键不能相同,可以通过键,找到值,字典最外面用大括号,每一组用冒号连接起来。

 (4) 集合相当于字典的键,也是一个无序不重复的元素集,用一对{}表示。

 

1.遍历输出列表元组字典集合

a = list('asdgj')  # 列表的遍历
print(a)
for i in a:
    print(i)

b = tuple('564454')  # 元组的遍历
print(b)
for i in b:
    print(i)

c = set('gutiu')  # 集合的遍历
print(c)
for i in c:
    print(i)

d = {'a': 222, 'b': 333, 'c': 666}  # 字典的遍历
print(d)
for i in d:
    print(i, d[i])

 

 




b1='https://edu.cnblogs.com/campus/gzcc/14NetworkEngineering/homework/870' b2=b1.split('/') classmates = ['Michael', 'Bob', 'Tracy','李三' ,'Tracy'] print(b1,b2) print(classmates[1]) print(classmates[1:3]) print(len(classmates)) print(max(classmates)) print(min(classmates)) print(classmates.index( 'Tracy')) print(classmates.count( 'Tracy')) classmates[1]='Sarah' print(classmates[1]) print(classmates) classmates.insert(1,'Jack') print(classmates) classmates.append('Adam') print(classmates) classmates.extend(b2) print(classmates) print(classmates.pop()) print(classmates.pop())

z1='''If You Want Me 
Marketa Irglova and Glen Hansard 
ONCE OST 
Are you really here 
or am I dreaming 
I can't tell dreams from truth 
For it's been so long 
since I have seen you 
I can hardly remember your face anymore 
When I get really lonely 
and the distance calls its only silence 
I think of you smiling 
with pride in your eyes a lover that sighs 
If you want me 
satisfy me 
If you want me 
satisfy me 
If You Want Me 
Once OST 
Glen Hansard and Marketa Irglova 
Are you really sure 
that you believe me 
When others say I lie 
I wonder if you could 
ever despise me 
When you know I really try 
To be a better one 
to satisfy you 
for you're everything to me 
And I do 
what you ask me 
If you let me be free 
If you want me 
satisfy me 
If you want me 
satisfy me 
If you want me 
satisfy me 
If you want me 
satisfy me 
If You Want Me 
Marketa Irglova and Glen Hansard 
ONCE OST
'''.lower()

s=''',。:!?’"'''
for me in s:
    z1=z1.replace(me,' ')
z1=z1.split()
print(z1)

strSet=set(z1)
for me in strSet:
    print(me,z1.count(me))

posted @ 2018-10-08 11:34  张龙坤  阅读(232)  评论(0)    收藏  举报