...
Code Block |
---|
strings = "my name is Chun Kang and Chun is my name" r = set(strings.split()) print(r) |
Find overlapped entries from two
...
arrays
Code Block |
---|
a = set([ "Seoul", "Pusan", "Incheon", "Mokpo" ]) b = set([ "Seoul", "Incheon", "Suwon", "Daejeon", "Gwangjoo", "Taeku"]) print(a.intersection(b)) print(b.intersection(a)) |
The result will be like below
Result |
---|
{'Seoul', 'Incheon'} {'Seoul', 'Incheon'} |
Find different elements from two arrays based on "symmetric_difference" method
Code Block |
---|
a = set(["Jake", "John", "Eric"])
b = set(["John", "Jill"])
print(a.symmetric_difference(b))
print(b.symmetric_difference(a)) |
The result will be like below
Result |
---|
{'Jake', 'Eric', 'Jill'} {'Eric', 'Jake', 'Jill'} |
Find different elements from two arrays based on "difference" method
Code Block |
---|
a = set(["Jake", "John", "Eric"])
b = set(["John", "Jill"])
print(a.difference(b))
print(b.difference(a)) |
The result will be like below
Result |
---|
{'Jake', 'Eric'} {'Jill'} |
Find different elements from two arrays based on "union" method
Code Block |
---|
a = set(["Jake", "John", "Eric"])
b = set(["John", "Jill"])
print(a.union(b)) |
The result will be like below
Result |
---|
{'John', 'Eric', 'Jake', 'Jill'} |