python - Find shortest substring -


I have written a code to find the substrings from the string. I print all this substrings but I think length 2 Need an object of up to 6 and print the minimum length of the substrings. Please help me

Program:

  import p = re.compile ('s (. +?) N') s = 'ASDFANSAAAAAFGNDASMPRKYN' s1 = p. Findall (s) Print S1  

Output:

 [code] ['Dfa', 'AAAAAFG', 'MPRKY']  

"Text">

If you already have a list, you can use the function as a second argument with the function.

  & gt; & Gt; & Gt; S1 = ['DFA', 'AAAAAFG', 'MPRKY'] & gt; & Gt; & Gt; Minimum (S1, Key = Lane) 'DFA'  

Edit:
This event has two equal lengths, you can extend it Create a list containing all the same length elements:

  gt; & Gt; S2 = ['Foo', 'Bar', 'False', 'Spam', 'Egg', 'Knight']> gt; & Gt; & Gt; S2_min_len = len (min (s2, key = len)> gt; & Gt; & Gt; ['F.U.', 'Bar', 'False']  

The above should work when only 1 'at least' element also

Edit 2: To be completed, at least according to my simple test, at least the length of the element should be calculated and used in it Understand the list. Updated above


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -