I am required to create a function that returns a list of all instances of single characters in 'text' that immediately follow 'last'. For example...

def follow_char(text,last):
>>> follow_char('as we consider the operations', 'co')


I think I am required to solve this using linked lists but am not sure how to do this, any help will be greatly appreciated, cheers =)

6 Years
Discussion Span
Last Post by isendre

There is many ways, if the text is big, usually you would build dictionary with letter pairs as keys (for example for random text generation).

Here is one example of more advanced way of doing it by list comprehension:

>>> def follow_char(big, small):
	return [c for n, c in enumerate(big[len(small):], len(small))
		if big[:n].endswith(small)]

>>> follow_char('as we consider the operations', 'co')
>>> follow_char('as we consider the operations coconut', 'co')
['n', 'c', 'n']
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.