Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import string
- import random
- def Get_number():
- x = int(input("Enter a number:\n"))
- return x
- def Usr_msg(x, y):
- """Print a message telling the user whether there were any
- duplicates, and if so how many"""
- if len(x) == len(y):
- print("The list had no duplicates")
- elif len(x) - len(y) == 1:
- print("The list had one duplicate")
- else:
- u = len(x) - len(y)
- print("The list had " + str(u) + " duplicates\n")
- def a_no_dup_set(a):
- """Generate list of elements in a without duplicates using sets"""
- b = list(set(a))
- return b
- def a_no_dup_loop(a):
- """Generate list of elements in a without duplicates using a loop"""
- b = []
- for i in a:
- if not i in b:
- b.append(i)
- return b
- x = Get_number()
- #Generate random list of letters
- a = random.choices(string.ascii_lowercase, k = x)
- a_no_dup = a_no_dup_set(a)
- #a_no_dup = a_no_dup_loop(a)
- print(a, a_no_dup, sep = "\n")
- Usr_msg(a, a_no_dup)
Add Comment
Please, Sign In to add comment