0920作业
总结列表,元组,字典,集合的联系与区别:
1、列表是可变的对象,可进行动态的增加、删除、更新,即str.pop()和str.extend()等操作,用[]表示。
2、元组和列表在结构上没有什么区别,唯一的差异在于元组是只读的,不能修改。元组用“()”表示。
3、字典是存储键值对数据的对象,字典的元素都是无序的,且键不能相同,可以通过键,找到值,字典最外面用大括号,每一组用冒号连接起来。
4、集合相当于字典的键,也是一个无序不重复的元素集,用一对{}表示。
英文词频统计:
1.下载一首英文的歌词或文章str
2.分隔出一个一个的单词list
3.统计每个单词出现的次数 dict
strBig = '''Loving strangers loving strangers Loving strangers Loving strangers loving strangers Loving strangers I’ve got a hole in my pocket where all the money has gone I’ve got a whole lot of work to do with your heart 'Cause it’s so busy mine’s not Loving strangers loving strangers Loving strangers Loving strangers loving strangers Loving strangers It’s just the start of the winter and I’m all alone but I’ve got my eye right on you Give me a coin and I'll take you to the moon Give me a beer and I’ll kiss you so foolishly Like you do when you lie when you’re not in my thoughts Like you do when you lie and I know it’s my imagination Loving strangers loving strangers Loving strangers Loving strangers loving strangers Loving strangers Loving strangers loving strangers Loving strangers Loving strangers loving strangers Loving strangers''' strList = strBig.split(' ') print(strList) strListSort = strList.sort( ) print(strListSort) print(strList) a=str.upper(strBig) print( "全部大写:" +a) b=str.lower(strBig) print( "全部小写:" +b) print(strBig.count('Run')) c=f=str.capitalize(strBig) print("首字母大写其余小写" +c) d=str.swapcase(strBig) print("大小写互换" +d) e=max(strBig) print("最大:"+e) f=min(strBig) print("最小:"+f) strSet=set(strList) for word in strSet: print(word,strList.count(word))
运行结果:
['Loving', 'strangers', 'loving', 'strangers\nLoving', 'strangers\nLoving', 'strangers', 'loving', 'strangers\nLoving', 'strangers\nI’ve', 'got', 'a', 'hole', 'in', 'my', 'pocket\nwhere', 'all', 'the', 'money', 'has', 'gone\nI’ve', 'got', 'a', 'whole', 'lot', 'of', 'work', 'to', 'do', 'with', 'your', "heart\n'Cause", 'it’s', 'so', 'busy', 'mine’s', 'not\nLoving', 'strangers', 'loving', 'strangers\nLoving', 'strangers\nLoving', 'strangers', 'loving', 'strangers\nLoving', 'strangers\nIt’s', 'just', 'the', 'start', 'of', 'the', 'winter', 'and', 'I’m', 'all', 'alone\nbut', 'I’ve', 'got', 'my', 'eye', 'right', 'on', 'you\nGive', 'me', 'a', 'coin', 'and', "I'll", 'take', 'you', 'to', 'the', 'moon\nGive', 'me', 'a', 'beer', 'and', 'I’ll', 'kiss', 'you', 'so', 'foolishly\nLike', 'you', 'do', 'when', 'you', 'lie\nwhen', 'you’re', 'not', 'in', 'my', 'thoughts\nLike', 'you', 'do', 'when', 'you', 'lie\nand', 'I', 'know', 'it’s', 'my', 'imagination\nLoving', 'strangers', 'loving', 'strangers\nLoving', 'strangers\nLoving', 'strangers', 'loving', 'strangers\nLoving', 'strangers\nLoving', 'strangers', 'loving', 'strangers\nLoving', 'strangers\nLoving', 'strangers', 'loving', 'strangers\nLoving', 'strangers']
None
['I', "I'll", 'I’ll', 'I’m', 'I’ve', 'Loving', 'a', 'a', 'a', 'a', 'all', 'all', 'alone\nbut', 'and', 'and', 'and', 'beer', 'busy', 'coin', 'do', 'do', 'do', 'eye', 'foolishly\nLike', 'gone\nI’ve', 'got', 'got', 'got', 'has', "heart\n'Cause", 'hole', 'imagination\nLoving', 'in', 'in', 'it’s', 'it’s', 'just', 'kiss', 'know', 'lie\nand', 'lie\nwhen', 'lot', 'loving', 'loving', 'loving', 'loving', 'loving', 'loving', 'loving', 'loving', 'me', 'me', 'mine’s', 'money', 'moon\nGive', 'my', 'my', 'my', 'my', 'not', 'not\nLoving', 'of', 'of', 'on', 'pocket\nwhere', 'right', 'so', 'so', 'start', 'strangers', 'strangers', 'strangers', 'strangers', 'strangers', 'strangers', 'strangers', 'strangers', 'strangers', 'strangers\nIt’s', 'strangers\nI’ve', 'strangers\nLoving', 'strangers\nLoving', 'strangers\nLoving', 'strangers\nLoving', 'strangers\nLoving', 'strangers\nLoving', 'strangers\nLoving', 'strangers\nLoving', 'strangers\nLoving', 'strangers\nLoving', 'strangers\nLoving', 'strangers\nLoving', 'strangers\nLoving', 'take', 'the', 'the', 'the', 'the', 'thoughts\nLike', 'to', 'to', 'when', 'when', 'whole', 'winter', 'with', 'work', 'you', 'you', 'you', 'you', 'you', 'you', 'you\nGive', 'your', 'you’re']
全部大写:LOVING STRANGERS LOVING STRANGERS
LOVING STRANGERS
LOVING STRANGERS LOVING STRANGERS
LOVING STRANGERS
I’VE GOT A HOLE IN MY POCKET
WHERE ALL THE MONEY HAS GONE
I’VE GOT A WHOLE LOT OF WORK TO DO WITH YOUR HEART
'CAUSE IT’S SO BUSY MINE’S NOT
LOVING STRANGERS LOVING STRANGERS
LOVING STRANGERS
LOVING STRANGERS LOVING STRANGERS
LOVING STRANGERS
IT’S JUST THE START OF THE WINTER AND I’M ALL ALONE
BUT I’VE GOT MY EYE RIGHT ON YOU
GIVE ME A COIN AND I'LL TAKE YOU TO THE MOON
GIVE ME A BEER AND I’LL KISS YOU SO FOOLISHLY
LIKE YOU DO WHEN YOU LIE
WHEN YOU’RE NOT IN MY THOUGHTS
LIKE YOU DO WHEN YOU LIE
AND I KNOW IT’S MY IMAGINATION
LOVING STRANGERS LOVING STRANGERS
LOVING STRANGERS
LOVING STRANGERS LOVING STRANGERS
LOVING STRANGERS
LOVING STRANGERS LOVING STRANGERS
LOVING STRANGERS
LOVING STRANGERS LOVING STRANGERS
LOVING STRANGERS
全部小写:loving strangers loving strangers
loving strangers
loving strangers loving strangers
loving strangers
i’ve got a hole in my pocket
where all the money has gone
i’ve got a whole lot of work to do with your heart
'cause it’s so busy mine’s not
loving strangers loving strangers
loving strangers
loving strangers loving strangers
loving strangers
it’s just the start of the winter and i’m all alone
but i’ve got my eye right on you
give me a coin and i'll take you to the moon
give me a beer and i’ll kiss you so foolishly
like you do when you lie
when you’re not in my thoughts
like you do when you lie
and i know it’s my imagination
loving strangers loving strangers
loving strangers
loving strangers loving strangers
loving strangers
loving strangers loving strangers
loving strangers
loving strangers loving strangers
loving strangers
0
首字母大写其余小写Loving strangers loving strangers
loving strangers
loving strangers loving strangers
loving strangers
i’ve got a hole in my pocket
where all the money has gone
i’ve got a whole lot of work to do with your heart
'cause it’s so busy mine’s not
loving strangers loving strangers
loving strangers
loving strangers loving strangers
loving strangers
it’s just the start of the winter and i’m all alone
but i’ve got my eye right on you
give me a coin and i'll take you to the moon
give me a beer and i’ll kiss you so foolishly
like you do when you lie
when you’re not in my thoughts
like you do when you lie
and i know it’s my imagination
loving strangers loving strangers
loving strangers
loving strangers loving strangers
loving strangers
loving strangers loving strangers
loving strangers
loving strangers loving strangers
loving strangers
大小写互换lOVING STRANGERS LOVING STRANGERS
lOVING STRANGERS
lOVING STRANGERS LOVING STRANGERS
lOVING STRANGERS
i’VE GOT A HOLE IN MY POCKET
WHERE ALL THE MONEY HAS GONE
i’VE GOT A WHOLE LOT OF WORK TO DO WITH YOUR HEART
'cAUSE IT’S SO BUSY MINE’S NOT
lOVING STRANGERS LOVING STRANGERS
lOVING STRANGERS
lOVING STRANGERS LOVING STRANGERS
lOVING STRANGERS
iT’S JUST THE START OF THE WINTER AND i’M ALL ALONE
BUT i’VE GOT MY EYE RIGHT ON YOU
gIVE ME A COIN AND i'LL TAKE YOU TO THE MOON
gIVE ME A BEER AND i’LL KISS YOU SO FOOLISHLY
lIKE YOU DO WHEN YOU LIE
WHEN YOU’RE NOT IN MY THOUGHTS
lIKE YOU DO WHEN YOU LIE
AND i KNOW IT’S MY IMAGINATION
lOVING STRANGERS LOVING STRANGERS
lOVING STRANGERS
lOVING STRANGERS LOVING STRANGERS
lOVING STRANGERS
lOVING STRANGERS LOVING STRANGERS
lOVING STRANGERS
lOVING STRANGERS LOVING STRANGERS
lOVING STRANGERS
最大:’
最小:
pocket
where 1
strangers
I’ve 1
to 2
winter 1
so 2
strangers
It’s 1
my 4
foolishly
Like 1
on 1
coin 1
has 1
just 1
alone
but 1
hole 1
I’ve 1
know 1
lot 1
moon
Give 1
you 6
of 2
I 1
I’ll 1
you
Give 1
kiss 1
your 1
I'll 1
work 1
whole 1
lie
and 1
Loving 1
beer 1
start 1
loving 8
with 1
lie
when 1
right 1
gone
I’ve 1
me 2
the 4
strangers
Loving 13
you’re 1
all 2
money 1
I’m 1
eye 1
when 2
not 1
mine’s 1
heart
'Cause 1
and 3
strangers 9
busy 1
thoughts
Like 1
imagination
Loving 1
it’s 2
take 1
do 3
not
Loving 1
got 3
in 2
a 4