Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools
- def generate_variations(string, length):
- variations = [''.join(comb) for comb in itertools.product(string, repeat=length)]
- return variations
- def write_variations_to_file(variations):
- with open('output.txt', 'w') as file:
- for variation in variations:
- file.write(variation + '\n')
- # Example usage
- string = input("Enter a string of characters: ")
- length = int(input("Enter the length: "))
- variations = generate_variations(string, length)
- write_variations_to_file(variations)
- print("Variations have been written to 'output.txt'.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement