Skip to content Skip to sidebar Skip to footer

To Output A String Without Whitespce

My program: def string_splosion(str): j=1 c=len(str) i=0 s='' while(i

Solution 1:

Currently, you are printing each iteration separately. Though you can get your example to work by changing the logic a little bit, this is an easy job for Python magic:

>>>s = 'Code'>>>''.join(s[:i+1] for i inrange(len(s)))
'CCoCodCode'

Solution 2:

You can try this :

defstring_data(str):
  result= ""for x inrange(len(str)):
    result = result + str[:x+1]
  return result

string_data('code')

Post a Comment for "To Output A String Without Whitespce"