Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ 1.) Understand the problem
- Take two lists, and write a program that returns a list that contains only the elements that are common between the lists
- (without duplicates).
- Make sure your program works on two lists of different sizes.
- 2.) Plan a solution
- Algorithm:
- - Change previous lists into sets
- - Create a new list
- - Make a for loop to iterate over one of the list
- - if the element in first list is the same as the element in the last
- - append to the new list
- - Change new list into set
- - Print new list
- 3.) Carry out the plan
- """
- a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
- set_a = set(a)
- b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
- set_b = set(b)
- c = []
- for x, y in zip(a, b):
- if x in b:
- c.append(x)
- c = set(c)
- print(c)
- """
- 4.) Examine your results for accuracy:
- Input:
- a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
- b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
- Output:
- c = [1, 2, 3, 5, 8, 13]
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement