Commit 3936c134 by BellCodeEditor

auto save

parent 602c70d2
import wordcloud
# 读取文本
with open('python二级考试大纲.txt','r',encoding='utf-8') as f:
text = f.read()
# 创建词云对象
w = wordcloud. WordCloud(background_color="white",font_path='SimHei.ttf')
# 传入词语文本内容
w.generate(text)
# 保存为png图片
w.to_file("mycloud.png")
\ No newline at end of file
import wordcloud
w = wordcloud. WordCloud(background_color="white",font_path='SimHei.ttf')
w.generate("贝尔编程")
w.to_file("mycloud.png")
\ No newline at end of file
import wordcloud
from PIL import Image
import numpy
# 读取文本
with open('python二级考试大纲.txt','r',encoding='utf-8') as f:
text = f.read()
img = Image.open('bell.png')
data = numpy.array(img)
img_colors = wordcloud.ImageColorGenerator(data)
# 创建词云对象
w = wordcloud. WordCloud(background_color="white",font_path='SimHei.ttf',
mask=data,color_func=img_colors)
# 传入词语文本内容
w.generate(text)
# 保存为png图片
w.to_file("mycloud.png")
\ No newline at end of file
import numpy as np
from PIL import Image
img = Image.open('6x2.png')
print(img)
value = np.array(img)
print(value)
from random import * # 导入随机模块
list=[randint(1,10) for i in range(15) ] # 随机100个1-50的随机数
print(list)
count = [0 for i in range(len(list))] # 对从0到列表长度的数值归0,准备计数
print(count)
for val in list: # 对列表进行遍历
# print(val,end='/')
count[val] +=1 # 计数的第遍历值的位置计数加1
# print(count[val])
print(count)
list.clear()
for i,j in enumerate(count): # 对计数中的索引和数据进行遍历 i是索引,j是数据
for k in range(j): # 将数据中的数值数量循环 就是计数中的计数次数
list.append(i)
print(list)
\ No newline at end of file
import jieba
text = "他来自北京大学"
txt_list = jieba.lcut(text)
print(txt_list)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment