How to make this code more efficient ? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

How to make this code more efficient ?

Basically i've seen this code in the internet. It displays a lightning bolt pattern in asterisk and i want to make it more efficient by putting an input field that accepts integer only. here's the code: from math import ceil as c lightning=lambda len : (" "*(len+1)+"*"*len+"\n"+"\n".join(" "*(len-i)+"*"+" "*(len-2)+"*" for i in range(len))+"\n*"+" "*(len-2)+"*"*(len*2-2)+"\n"+"\n".join("*"+" "*(len*3-5)+"*"for i in range(c(len/2)-(2 if len >4 else 1)))+"\n"+"*"*(len*2-3)+" "*(len-2)+"*"+"\n"+"\n".join(" "*(len*2-5-i)+"*"+" "*(len-2)+"*" for i in range(len-1))+"\n"+" "*(len-4)+"*"*len) if len > 3 else"" for i in range(2,5): print(lightning(i))

3rd Dec 2019, 8:14 AM
Uganda warrior
Uganda warrior - avatar
1 Resposta
0
This is quite good honestly but i was also scratching my head to do this the first time in a efficient way.
3rd Dec 2019, 1:36 PM
Uganda warrior
Uganda warrior - avatar