python - Cut off string after a certain length -
i wrote code:
name = 'programmstrukturen 2' num1=5 num2='$' lang_name=len(name) m_res=lang_name % num1 x in range(num1): print 'x =' + str(x) print 'num1='+str(x) print name[x] + name[x+num1] + name[x+num1+num1] + name[x+num1+num1+num1]
what pretty easy, prints i+4 + i+4+4 + i+4+4+4 chars amount of num1. working , there chance improve loop reducing last line ? , put outputs one?
current output:
x =0 num1 =0 parr x =1 num1 =1 rmue x =2 num1 =2 omkn x =3 num1 =3 gst x =4 num1 =4 rtu2
wished output:
parrrmueomkngst rtu2
can done += or .join ?
name = 'programmstrukturen 2' num1=5 output='' x in range(num1): in range(num1-1): output+=name[x+num1*i] #you simplify long line print output
>>> parrrmueomkngst rtu2
Comments
Post a Comment