<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>04 Sets :: My Site</title><link>https://trungnte.github.io/my-fcj-blog/python/04-sets/index.html</link><description>1. Overview Set: is an unordered collection of unique objects. A set can be created from a tuple or list Shell &gt;&gt;&gt; a = [3, 4, 5] &gt;&gt;&gt; s = set(a) &gt;&gt;&gt; print(s) {3, 4, 5} &gt;&gt;&gt; type(s) &lt;class 'set'&gt; 2. Some notes 2.1 Duplicates Important Duplicates are ignored
Shell &gt;&gt;&gt; a = [3, 4, 5] &gt;&gt;&gt; s = set(a) &gt;&gt;&gt; print(s) {3, 4, 5} &gt;&gt;&gt; type(s) &lt;class 'set'&gt; &gt;&gt;&gt; &gt;&gt;&gt; a = [3, 3, 5] &gt;&gt;&gt; s = set(a) &gt;&gt;&gt; print(s) {3, 5} &gt;&gt;&gt; 2.2 The | operator and the &amp; operator Shell &gt;&gt;&gt; a = set([3, 4, 5]) &gt;&gt;&gt; b = set([4, 5, 6]) &gt;&gt;&gt; print(a) {3, 4, 5} &gt;&gt;&gt; print(b) {4, 5, 6} &gt;&gt;&gt; print(a | b) {3, 4, 5, 6} &gt;&gt;&gt; print(a &amp; b) {4, 5} &gt;&gt;&gt; 2.3 The - operator and the ^ operator Shell &gt;&gt;&gt; print(a) {3, 4, 5} &gt;&gt;&gt; print(b) {4, 5, 6} &gt;&gt;&gt; print(b - a) {6} &gt;&gt;&gt; print(b ^ a) {3, 6} &gt;&gt;&gt;</description><generator>Hugo</generator><language>en</language><lastBuildDate/><atom:link href="https://trungnte.github.io/my-fcj-blog/python/04-sets/index.xml" rel="self" type="application/rss+xml"/></channel></rss>