-
-
Save cuppster/3364712 to your computer and use it in GitHub Desktop.
Simple String Generator in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
def string_patterns(pattern, *args): | |
'''generator for string patterns''' | |
for data in itertools.product(*args): | |
s = pattern.format(*data) | |
yield s | |
# generate some urls! | |
for url in string_patterns('http://example.com/{0}/{1}', ['page'], range(1,5)): | |
print url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment