python - Adding spaces in elements of list(PY) -


i have problem:

i have list consists of elements of different lenghts: det_slopes_jkh = ['superpipe bolgen','jatzpark','avalanch training center','bräma schwer']

and add spaces ' ' shorter words, purpose of having elements of list same lenght.

det_slopes_jkh2 = [] element in det_slopes_jkh:      if len(element) < len(element[2]:          det_slopes_jkh2.append(element + ' ') 

thanks

your goal not clear assuming want have strings of same length.

this adds space each string until of same length (the length of longest string):

def equalize_lengths(l):     length = len(max(l, key=len))     return [e.ljust(length) e in l] 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -