Skip to content

Instantly share code, notes, and snippets.

@pleasedontbelong
Created April 30, 2018 08:41
Show Gist options
  • Save pleasedontbelong/d4b7c56c7cd49ca629e9eccff5779c64 to your computer and use it in GitHub Desktop.
Save pleasedontbelong/d4b7c56c7cd49ca629e9eccff5779c64 to your computer and use it in GitHub Desktop.
import re
phrase = "we are ______,______ and ___"
names = ["John", "Paul", "Ringo"]
re.sub(r'(_)\1{2,}', something, phrase)
"we are John,Paul and Ringo"
@pleasedontbelong
Copy link
Author

import re
phrase = "we are ______,______ and _____"
names = ["John", "Paul", "Ringo"]


def name_replace(match):
    name = names.pop(0)
    return name

print(re.sub(
    r'(_)\1{2,}',
    name_replace,
    phrase
))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment