Home > other >  How to turn a string according to the statistics of 26 letters to a 0 to 25 subscript strings?
How to turn a string according to the statistics of 26 letters to a 0 to 25 subscript strings?

Time:11-18

How to turn a string in accordance with the 26 letters classified into a 0 to 25 subscript strings? The Python language,

For example:
"Abcdefgaj
"Array: a

A [0]=2 (two)
A [1]=1 (a b)
.

I don't think the if too much trouble

CodePudding user response:

https://www.cnblogs.com/longyuu/p/9787512.html

CodePudding user response:

https://blog.csdn.net/qq_40674583/article/details/81591211? Utm_medium=distribute. Pc_relevant. None - task - blog - BlogCommendFromMachineLearnPai2-1. Channel_param & amp; Depth_1 - utm_source=distribute. Pc_relevant. None - task - blog - BlogCommendFromMachineLearnPai2-1. Channel_param
There will be combined with the, can be finished

CodePudding user response:

Yet I didn't think written without the if

 
Input_str=input (" please enter: ")

A='
S_list=[]

# will all elements into the list
For I in input_str:
S_list. Append (I)

# to heavy
S_set=set (s_list)

For I in range (97, 123) :
# CRH (97) - & gt; A CRH (122) - & gt; Z
If CRH (I) in s_set:
A +=f '{s_list. Count (CRH) (I)}'
The else:
A +='0'

Print (a)

CodePudding user response:

Looking to a need not the if, correct:
 # to ensure that the input string to lowercase letters, otherwise the index out of range 
Input_str=input (" please input lowercase string (no Spaces) : ')
S_list=list (input_str)
A=[0 for x in the range (26)]
For x in s_list:
A [word] (x) - 97 +=1
Print (a)

CodePudding user response:

From the collection import Counter

Print (Counter (' abcdefgaj))

Cell phone tapping, first try

CodePudding user response:

 import string 
The import itertools as it

S="abccdefgaj"

G=it. Groupby (sorted (s))
D={I: len (list (j)) for I and j in g}
S={" a [] {} ". The format (I) : d.g et (j, 0) for the I, j in enumerate (string. Ascii_letters)}
Print (s)

CodePudding user response:

Just use some code conversion, I don't need to bother
A some code I remember is the 41 h 85
Starting from the 85 + 1
  • Related