Попробуйте следующий код. Я добавил комментарии для лучшего понимания.
original_string = input("Lists: ")
splitted_input = original_string.split(';') # split the input string into two lists of String
list1 = [int(i) for i in splitted_input[0].split()] # convert first String (before semi-colon) into list of int
list2 = [int(i) for i in splitted_input[1].split()] # convert second String (after semi-colon) into list of int
l1 = list(set([x for x in list1 if list1.count(x) > 1])) # List of only repeated numbers in list1
l2 = list(set([x for x in list2 if list2.count(x) > 1])) # List of only repeated numbers in list2
l = l1 + l2
final_list = list(set([x for x in l if l.count(x) > 1])) # List of only repeated numbers in l
final_list_sorted = sorted(final_list) # sort the list in ascending order
print('Two lists before and after semi-colin are: ', list1, list2)
print('Two lists with only repeated numbers are: ', l1, l2)
print('Final list with repeated numbers in both the lists in an ascending order is: ', final_list_sorted)
Выход:
Lists: 1 3 4 2 1 2 1 3; 4 4 2 4 3 2 4 4 3 1 3
Two lists before and after semi-colin are: [1, 3, 4, 2, 1, 2, 1, 3] [4, 4, 2, 4, 3, 2, 4, 4, 3, 1, 3]
Two lists with only repeated numbers are: [1, 2, 3] [2, 3, 4]
Final list with repeated numbers in both the lists in an ascending order is: [2, 3]
Lists: 1 1 2 3 4 5; 2 3 4 5 6
Two lists before and after semi-colin are: [1, 1, 2, 3, 4, 5] [2, 3, 4, 5, 6]
Two lists with only repeated numbers are: [1] []
Final list with repeated numbers in both the lists in an ascending order is: []
Lists: ;
Two lists before and after semi-colin are: [] []
Two lists with only repeated numbers are: [] []
Final list with repeated numbers in both the lists in an ascending order is: []