1.输入一个整数列表L,判断L中是否存在相同的数字:

(1)若存在,输出YES,否则输出NO;

(2)若存在,输出YES,同时输出相同的数字;否则输出NO。

 l=list(input())
print(l)
if len(l)==len(set(l)):
print('NO')
else:
for i in list(set(l)):
l.remove(i)
print('YES',' '.join(l))

2.从英文字母(区分大小写)和 0~9数字组成的列表中随机生成10个6位数的密码。

 import random

 l=[]
l+=list(range(10))
l+=[chr(i) for i in range(65, 91)]
l+=[chr(i) for i in range(97, 123)] res=[]
for i in range(10):
s=''
for j in range(6):
s+=str(l[random.randint(0,len(l)-1)])
res.append(s)
print('\n'.join(res))

3.从网上自行下载一个长篇英文小说,统计并输出该小说中词频最大的TOP 20结果。利用该文本和wordcloud库、imageio库等,生成一个属于自己的词云图形。

 import jieba
import wordcloud
import imageio txt=open("./trial-python/achristmascarol.txt","r",encoding="utf-8").read()
words=jieba.lcut(txt)
counts={}
for word in words:
if len(word)==1 and ord(word) not in range(65,91) and ord(word) not in range(97,123):
continue
else:
counts[word]=counts.get(word,0)+1 items=list(counts.items())
items.sort(key=lambda x: x[1],reverse=True)
for i in range(20):
word,count=items[i]
print("{0:<2}:{1:<10}{2:>5}".format(i+1,word,count))
w=wordcloud.WordCloud(width=1000,height=700,background_color="white")
w.generate_from_frequencies(counts)
w.to_file("./trial-python/achristmascarol.png")

4.从网上自行下载一个长篇中文小说(除课堂讲授的三国演义外),统计并输出该小说中词频最大的TOP 20结果。利用该文本和jieba库、wordcloud库、imageio库等,生成一个属于自己的词云图形。

import jieba
import wordcloud
import imageio txt=open("./trial-python/thestoryofthestone.txt","r",encoding="utf-8").read()
words=jieba.lcut(txt)
counts={}
for word in words:
if len(word)==1:
continue
else:
counts[word]=counts.get(word,0)+1
items=list(counts.items())
items.sort(key=lambda x: x[1],reverse=True)
for i in range(20):
word,count=items[i]
print("{0:<2}:{1:<10}{2:>5}".format(i+1,word,count))
w=wordcloud.WordCloud(width=1000,height=700,font_path="msyh.ttc",background_color="white")
w.generate_from_frequencies(counts)
w.to_file("./trial-python/thestoryofthestone.png")

python初学(二)的更多相关文章

  1. 初学Python(二)——数组

    初学Python(二)——数组 初学Python,主要整理一些学习到的知识点,这次是数组. # -*- coding:utf-8 -*- list = [2.0,3.0,4.0] #计算list长度 ...

  2. 孤荷凌寒自学python第四十五天Python初学基础基本结束的下阶段预安装准备

     孤荷凌寒自学python第四十五天Python初学基础基本结束的下阶段预安装准备 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 今天本来应当继续学习Python的数据库操作,但根据过去我自 ...

  3. Python初学笔记之字符串

    一.字符串的定义 字符串是就一堆字符,可以使用""(双引号).''(单引号)来创建. 1 one_str = "定义字符串" 字符串内容中包含引号时,可以使用转 ...

  4. Python初学笔记

    一.安装:直接通过软件管理程序,搜索Python,安装:安装过程中自定义路径,有个选项类似“add Python3.5 to Path”,勾选后便可以在cmd命令窗口,通过输入Python,启动Pyt ...

  5. Python 基础 二

    Python 基础 二 今天对昨天学习的Python基础知识进行总结,学而不思则惘,思而不学则殆! 一.先对昨天学习的三大循环的使用情况进行总结: 1.while循环的本质就是让计算机在满足某一条件的 ...

  6. Python学习二:词典基础详解

    作者:NiceCui 本文谢绝转载,如需转载需征得作者本人同意,谢谢. 本文链接:http://www.cnblogs.com/NiceCui/p/7862377.html 邮箱:moyi@moyib ...

  7. 有关python下二维码识别用法及识别率对比分析

    最近项目中用到二维码图片识别,在python下二维码识别,目前主要有三个模块:zbar .zbarlight.zxing. 1.三个模块的用法: #-*-coding=utf-8-*- import ...

  8. PYTHON练习题 二. 使用random中的randint函数随机生成一个1~100之间的预设整数让用户键盘输入所猜的数。

    Python 练习 标签: Python Python练习题 Python知识点 二. 使用random中的randint函数随机生成一个1~100之间的预设整数让用户键盘输入所猜的数,如果大于预设的 ...

  9. 从Scratch到Python——Python生成二维码

    # Python利用pyqrcode模块生成二维码 import pyqrcode import sys number = pyqrcode.create('从Scratch到Python--Pyth ...

  10. 用python生成二维码

    Python生成二维码,可以使用qrcode模块, github地址 我是搬运工 首先安装, 因为打算生成好再展示出来,所以用到Pillow模块 pip install qrcode pip inst ...

随机推荐

  1. C# UDP通讯实例

    1.发送方代码 void SendMsg(string toip, int port ) { try { string message="发送内容"; UdpClient udpc ...

  2. python编写“求最大值”

    # 求最大值 def large(*num): # 定义一个large函数,函数的参数为可变参数 ma = num[0] # 初始化最大值 for n in num: if ma < n: # ...

  3. 国际惯例,Hello World。

    c语言: #include<stdio.h> int main() { printf("Hello World!\n"); ; } C++: #include<i ...

  4. drf-jwt的过滤,筛选,排序,分页组件

    目录 自定义drf-jwt配置 案例:实现多方式登陆签发token urls.py models.py serializers.py views.py 案例:自定义认证反爬规则的认证类 urls.py ...

  5. python学习(五)之列表元素的积

    前几天,学完python的列表之后,我们老师留了一道关于列表的题目.几天后,老师讲解习题,很荣幸成为被老师点名讲解自己代码的其中之一下面把我的想法分享一下. 描述一个由n(n>1)个数字组成的列 ...

  6. 多线程设计模式——Read-Write Lock模式和Future模式分析

    目录 多线程程序评价标准 任何模式都有一个相同的"中心思想" Read-Write Lock 模式 RW-Lock模式特点 冲突总结 手搓RW Lock模式代码 类图 Data类 ...

  7. socket,实现服务器和客户端对话

    服务器: #define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string>#include<WinSock ...

  8. mongodb的增加和删除

    一  mongodb中使用insert()方法来增加集合中的文档: db.myTable.insert({name:'arvin',age:12}) //对名为myTable的集合插入数据 插入数据 ...

  9. 【tensorflow2.0】处理结构化数据-titanic生存预测

    1.准备数据 import numpy as np import pandas as pd import matplotlib.pyplot as plt import tensorflow as t ...

  10. Matlab——m_map指南(3)——实例

    m_map 实例 1. clear all m_proj('ortho','lat', 48,'long',-123');%投影方式,范围 m_coast('patch','r');%红色填充 m_g ...