Search code examples
pythonpython-3.xframeworkspep8sentence-synthesis

Sentence variations in python3


A few months ago I found something with this kind of syntax:

{Hello|Dear} {Customer|client|person},

xxxx

This will generate sentences like:

Hello Customer,

or

Dear person,

How is it called? Is there a framework which parses this? If not, how would I do this?

I am planning to use this in an automation script which builds sentences.

Any further idea's on which frameworks I should use for building sentences in python? It makes ugly code when long blocks of text are embedded in python scripts.


Solution

  • If you want random greetings,

    import random
    greetings = ["hello", "dear"]
    print("{} person".format(str(random.choice(greetings))))