Home > other >  Pray god help python programming
Pray god help python programming

Time:10-02

CodePudding user response:

Through regular way to come up with an answer

Make a reference

 
The import re

Input_str=input (' please input string:)
Exist_str=set (input_str) # string to heavy

Co_len_max=0

For I in exist_str:
# through regular search co - string
Co_list=re. The.findall (' [{}] * {} ({}) * '. The format (I, I, I), input_str)
# to pick up the co - string in each list, check the length of the
Co_str=co_list [0]
Co_str_len=len (co_str)
If co_str_len & gt; Co_len_max and co_str_len & gt; 1:
# will be the biggest length assigned to co_len_max
Co_len_max=co_str_len

Print (co_len_max)

CodePudding user response:

Just now the code is not comprehensive, the same character appear multiple times (abcaaaabbbbb)

The output will go wrong

The optimized code
 
The import re

Input_str=input (' please input string:)
Exist_str=set (input_str) # string to heavy

Co_len_max=0

For I in exist_str:
# through regular search co - string
Co_list=re. The.findall (' [{}] * {} ({}) * '. The format (I, I, I), input_str)
Print (co_list)
# to pick up the co - string in each list, check the length of the
For j in range (len (co_list) :
Co_str=co_list [j]
Co_str_len=len (co_str)
If co_str_len & gt; Co_len_max and co_str_len & gt; 1:
# will be the biggest length assigned to co_len_max
Co_len_max=co_str_len

Print (co_len_max)
  • Related