Home > other >  Can help explain the code
Can help explain the code

Time:10-24

Import the random
A=[random randint (0, 20) for I in range (10)]
Print (a)
B=sorted (a)
C={}
For I in b:
If I in c:
C=c [I] [I] + 1
The else:
[I] c=1
Print (c)

CodePudding user response:

 
Import the random
10 # a list, cycle times, each time to extract an integer (0-20), added to the list
A=[random randint (0, 20) for I in range (10)]
Print (a)
# sorting, assigned to the new order b
B=sorted (a)
C={}
# traverse the list b
For I in b:
# to judge the key in not in the dictionary
If I in c:
# if you have the key, its value is + 1
C=c [I] [I] + 1
The else:
# if you don't have the key, its value is 1
[I] c=1
Print (c)

CodePudding user response:

 
Import the random
A=[random randint (0, 20) for I in range (10)] generated 10 # 0-19 (including 0 and 19) between the random Numbers, and stored in a list in a
Print (a)
B=sorted # (a) to a sorting
C={} # define a dictionary
For I in b: # after traversal sequence of a
If I in c # if a value in c
C=c [I] [I] value + 1 + 1 # c
The else:
[I] c=1 # initialization
Print (c)

# the meaning of the whole piece of code: the number of statistics random number
  • Related