- #1
shivajikobardan
- 674
- 54
I want to find difference between two list. I came across sth called list comprehension. I can't tell you how confused I am with this.
My confusion lies here-:
What is happening here? I can't understand a single word. How to understand this please guide me.
Also can you guide a link to how to write latex in this site(how to write math? I am familiar with stackexchange mathjax can I use that here?)
Code:
# Python 3 code to demonstrate
# to remove elements present in other list
# using list comprehension
# initializing list1
list1 = [1, 3, 4, 6, 7]
# initializing list2
list2 = [3, 6]
# printing list1
print("The list1 is : " + str(list1))
# printing list2
print("The list2 is : " + str(list2))
# using list comprehension to perform task
res = [i for i in list1 if i not in list2]
# printing result
print("The list after performing remove operation is : " + str(res))
My confusion lies here-:
Code:
res = [i for i in list1 if i not in list2]
What is happening here? I can't understand a single word. How to understand this please guide me.
Also can you guide a link to how to write latex in this site(how to write math? I am familiar with stackexchange mathjax can I use that here?)