Search code examples
pythonlistnlptuplestoken

Convert a list of bigram tuples to a list of strings


I am trying to create Bigram tokens of sentences. I have a list of tuples such as

tuples = [('hello', 'my'), ('my', 'name'), ('name', 'is'), ('is', 'bob')]

and I was wondering if there is a way to convert it to a list using python, so it would look love this:

list = ['hello my', 'my name', 'name is', 'is bob']

thank you


Solution

  • Try this snippet:

    list = [' '.join(x) for x in tuples]
    

    join is a string method that contatenates all items of a list (tuple) within a separator defined in '' brackets.