python string contains 1000 first generates random characters, then count the number of occurrences of each character

Title: first generate a random string contains 1000 characters, then count the number of occurrences of each character

String Import 
Import Random 
X = string.ascii_letters string.digits + + string.punctuation 
# Print (X) 
Y = [The random.choice (X) for I in Range (10)] # 1000 generates a string of random characters 
# Print (Y) 
D = dict () # using the dictionary stored number of occurrences of each character 
for ch in Y: 
    D [ch] = d.get (ch, 0) + # d.get. 1 (ch, 0) return occur ch number, if there is no return 0

  

Guess you like

Origin www.cnblogs.com/jiaxinwei/p/11610640.html