- Make List a String: Let's make the list ["Life", "is", "too", "short"] into a "Life is too short" string and print it out.
First, Let me tell you i know the way to solve the problem using join() method.
I wanted to solve this using another method, and i used for statement as below.
liszt = ['Life', 'is', 'too', 'short']restr = ''for i in liszt: restr += i+'' if liszt.index(i) != 3 else restr += iprint(restr)How can i correct this in valid syntax?or... is there any simpler way to code this than mine?
At that time, I intended to express same thing as below using one line. But editor told me it's invalid syntax.
liszt = ['Life', 'is', 'too', 'short']restr = ''for i in liszt: if liszt.index(i) != 3: restr += i+'' else: restr += iprint(restr)