How can i get the common elements in the first two list and save to a new list in python 3?

list1 = [input("Enter the values for the first list: ")]
list2 = [input("Enter the values for the second list: ")]
print(list1)
print(list2)
list3 = []
for element in list1:
    if element in list2:
        list3 = list2.append(element)
print(list3)

This is what i have tried. but I am getting an empty list as list3!

Answer

list1 = [input("Enter the values for the first list: ")]
list2 = [input("Enter the values for the second list: ")]

list1 and list2 will be a list of string. hence you are getting list3 empty. PFB code and o/p:

list1 = [input("Enter the values for the first list: ")]
list2 = [input("Enter the values for the second list: ")]
print(list1)
print(list2)
list3 = []
for element in list1:
    print(type(element))
    if element in list2:
        list3.append(element)

print(list3)

output:

Enter the values for the first list: 1 2 3 4 5
Enter the values for the second list: 2 3 4 5 6 
['1 2 3 4 5']
['2 3 4 5 6']
<class 'str'>
[]

to add the correct way. Please see below eg. for getting list1 and list2:

# list1 = [input("Enter the values for the first list: ")]
# list2 = [input("Enter the values for the second list: ")]
list1 = [int(item) for item in input("Enter the 1st list items : ").split()]
list2 = [int(item) for item in input("Enter the 2nd list items : ").split()]

print('1st list: ',list1)
print('2nd list: ',list2)
list3 = []
for element in list1:
    if element in list2:
        list3.append(element)

print('common: ', list3)

output:

Enter the 1st list items : 1 2 3 4 5
Enter the 2nd list items : 3 4 5 6 7
1st list:  [1, 2, 3, 4, 5]
2nd list:  [3, 4, 5, 6, 7]
common:  [3, 4, 5]