An important function of randomness is random, know random.randint(a,b) #,a,b Refers to the interval , This problem is solved .
This problem has two main points , One is four + Integers , The second is in reverse order
In reverse order, if you follow the common idea : One number, one number, and then sort , Because numbers can't be sliced , If we first convert a number into a string (str, A string can be a sequence , Can index 、 Slicing, etc. ), Reverse sort string and convert to integer type (int), It's a lot easier , Here are two ways to write :
This question has three points :
One is to randomly generate a list : To introduce random, Here you need to pay attention to the concept of lists []
The second is to disrupt the order :shuffle( Disrupt the sequence locally )
Third, calculation : Need to introduce numpy,python Basic computing functions in
The difficulty of this problem is how to make sure that there is a capital letter 、 A lowercase letter 、 And number , We need to introduce string function
The first speech.txt Put it in the file directory ( You can also put it elsewhere , Then use relative path or absolute path )
Here are three knowledge points :
1) Read text , Flow operation , Remember to open it. , operation ( Read or write ), close ( Avoid memory impact )
2) Count the number of words in the text
3) Count the words in the text , Need to introduce jieba
f.read(...) The writing of has included close
There is no need to traverse when counting words ( Although the underlying logic is the same ), Use the list to deduce the formula directly ( Also called grammar sugar )
Students who do data analysis may be used to pandas To write , Here is also a demonstration .
use pandas Read out the data , Others follow numpy equally
I have been wondering whether there is a shortcut key to copy the current line to the next line , Who knows about it , Reply in the comment area ~