def sequence_generator(limit):
""" A generator to create strings of pattern -> string1,string2..stringN """
inc = 0
while inc < limit:
yield 'string' + str(inc)
inc += 1
# To generate a generator. Notice I have used () instead of []
a_generator = (s for s in sequence_generator(10))
# To generate a list
a_list = [s for s in sequence_generator(10)]
# To generate a string
a_string = '['+ ", ".join(s for s in sequence_generator(10)) + ']'
myoldlist_1 = [[' myoldword'], [''], ['tttt myoldword'], ['jjjj ddmyoldwordd']]
No_ofposition = []
mynewlist_2 = []
for i in xrange(0, 4, 1):
mynewlist_2.append([x.replace('myoldword', "%s" % i + "_mynewword") for x in myoldlist_1[i]])
if len(mynewlist_2[i]) > 0:
No_ofposition.append(i)
mynewlist_2
No_ofposition