| 17 | import string |
| 18 | |
| 19 | def generate_random_string(length, use_uppercase=True, use_lowercase=True, use_digits=True, use_punctuation=False): |
| 20 | characters = '' |
| 21 | if use_uppercase: |
| 22 | characters += string.ascii_uppercase |
| 23 | if use_lowercase: |
| 24 | characters += string.ascii_lowercase |
| 25 | if use_digits: |
| 26 | characters += string.digits |
| 27 | if use_punctuation: |
| 28 | characters += string.punctuation |
| 29 | |
| 30 | if not characters: |
| 31 | raise ValueError("At least one character set must be selected") |
| 32 | |
| 33 | return ''.join(random.choice(characters) for i in range(length)) |
| 34 | |
| 35 | def find_most_matched_string(word_list, target): |
| 36 | # Get close matches; n=1 ensures only the top match is returned |