You can use zip
and string.split
:
def biword(string):
s = string.split()
return zip(s, s[1:])
>>> result = biword("There have been biographies of Dewey that briefly describe his system, but this is the first attempt to provide a detailed history of the work that more than any other has spurred the growth of librarianship in this country and abroad.")
>>> list(result)
[('There', 'have'), ('have', 'been'), ('been', 'biographies'), ('biographies', 'of'), ('of', 'Dewey'), ('Dewey', 'that'), ('that', 'briefly'), ('briefly', 'describe'), ('describe', 'his'), ('his', 'system,'), ('system,', 'but'), ('but', 'this'), ('this', 'is'), ('is', 'the'), ('the', 'first'), ('first', 'attempt'), ('attempt', 'to'), ('to', 'provide'), ('provide', 'a'), ('a', 'detailed'), ('detailed', 'history'), ('history', 'of'), ('of', 'the'), ('the', 'work'), ('work', 'that'), ('that', 'more'), ('more', 'than'), ('than', 'any'), ('any', 'other'), ('other', 'has'), ('has', 'spurred'), ('spurred', 'the'), ('the', 'growth'), ('growth', 'of'), ('of', 'librarianship'), ('librarianship', 'in'), ('in', 'this'), ('this', 'country'), ('country', 'and'), ('and', 'abroad.')]
FYI, if you want to make the code in the function one line you can use an assignment expression (but that's a little overdoing it):
zip(s := string.split(), s[1:])