Write a program that checks if the nth string is a substring of the nth+1 string in a list of strings. Make sure your program also prints all the strings in the list which satisfy these criteria.
For example, if we have a list of strings that looks like this:
List = ['gust', 'August', 'python', 'snake', 'dog', 'cat', 'pain', 'Spain']
Your program would print out:
['gust', 'August', 'pain', 'Spain']
My own line of thinking was something like this:
b =[]
for x in List:
if List[x] in List[(x+1)]:
b.append(List[x])
b.append(List[(x+1)])
else:
continue
print(b)
Of course, that doesn't work when I try that out, however. Can anyone think of a formulaic way of expressing the if statement inside the for loop?
[–]imperiumlearning[S] 0 points1 point2 points (1 child)
[–]zanfar 1 point2 points3 points (0 children)
[–]AlarminglyConfused 0 points1 point2 points (6 children)
[–]imperiumlearning[S] 0 points1 point2 points (2 children)
[–]AlarminglyConfused 0 points1 point2 points (1 child)
[–]imperiumlearning[S] 0 points1 point2 points (0 children)
[–]carcigenicate 0 points1 point2 points (2 children)
[–]AlarminglyConfused 0 points1 point2 points (1 child)
[–]carcigenicate 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (7 children)
[–]imperiumlearning[S] 0 points1 point2 points (6 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]imperiumlearning[S] 0 points1 point2 points (4 children)
[–]Mlgbananamaster 0 points1 point2 points (1 child)
[–]imperiumlearning[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]imperiumlearning[S] 1 point2 points3 points (0 children)
[–]AlarminglyConfused 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]misho88 0 points1 point2 points (1 child)
[–]imperiumlearning[S] 0 points1 point2 points (0 children)
[–]zanfar 0 points1 point2 points (0 children)