Exercise 87

Given a list L, write a Python algorithm to convert a list into a string without using any predefined method other than the str() method. Example if L = ["Python", "created on", 91, "by Guido Van Rosam"], the algorithm returns the string s = "Python created on 91 by Guido Van Rosam".

Solution

L = ["Python", "created on", 91, "by Guido Van Rosam"]

# initialization of the chain s
s = ""
for word in L:
s = s + str (word) + " "

print (s) # output: 'Python created on 91 by Guido Van Rosam'
Younes Derfoufi
my-courses.net

Leave a Reply