<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>lists in python Archives -</title>
	<atom:link href="https://mitindia.in/tag/lists-in-python/feed/" rel="self" type="application/rss+xml" />
	<link>https://mitindia.in/tag/lists-in-python/</link>
	<description></description>
	<lastBuildDate>Sat, 19 Oct 2019 12:52:06 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://mitindia.in/wp-content/uploads/2023/03/cropped-android-chrome-512x512-1-32x32.png</url>
	<title>lists in python Archives -</title>
	<link>https://mitindia.in/tag/lists-in-python/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Collections in Python</title>
		<link>https://mitindia.in/collections-in-python/</link>
		
		<dc:creator><![CDATA[SKB]]></dc:creator>
		<pubDate>Sat, 19 Oct 2019 12:44:38 +0000</pubDate>
				<category><![CDATA[Artificial Intelligence]]></category>
		<category><![CDATA[Machine Learning]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[dictionary in python]]></category>
		<category><![CDATA[lists in python]]></category>
		<category><![CDATA[sets in python]]></category>
		<category><![CDATA[tuples in python]]></category>
		<guid isPermaLink="false">http://www.mitindia.in/?p=1001</guid>

					<description><![CDATA[<p>Collections in Python There are four collection data types in the Python language: List: A list is a data structure in Python that is a mutable, or changeable, ordered sequence of elements. Tuple: A tuple is a sequence of unchangeable Python objects. Set: A Set is an unordered collection data type that is iterable, changeable, and has no [&#8230;]</p>
<p>The post <a href="https://mitindia.in/collections-in-python/">Collections in Python</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1>Collections in Python</h1>
<p>There are four collection data types in the Python language:</p>
<ul>
<li><span style="color: #000080;"><strong>List</strong>: A list is a data structure in Python that is a mutable, or changeable, ordered sequence of elements.</span></li>
<li><span style="color: #000080;"><strong>Tuple:</strong> A tuple is a sequence of unchangeable Python objects.</span></li>
<li><span style="color: #000080;"><strong>Set</strong>: A Set is an unordered collection data type that is iterable, changeable, and has no duplicate items. </span></li>
<li><span style="color: #000080;"><strong>Dictionary</strong>: Python dictionary is an unordered collection of elements. A dictionary has a key and value combination.<br />
</span></li>
</ul>
<p><span style="color: #800000;"><strong># Using Lists in python</strong></span><br />
m=[&#8216;Apple&#8217;,&#8217;Orange&#8217;,&#8217;Cherry&#8217;]<br />
print(&#8220;Given list:&#8221;, m)</p>
<p>#Reverse list<br />
m.reverse()<br />
print(&#8220;Reverse List:&#8221;,m)</p>
<p># Appending list<br />
m.append(&#8216;Banana&#8217;)<br />
print(&#8220;Appending list:&#8221;,m)</p>
<p># Copying list from one to another<br />
n=m.copy()<br />
print(&#8220;Copying list from one to another:&#8221;,n)</p>
<p>#inserting elements at index position<br />
m.insert(1,&#8217;Kiwi&#8217;)<br />
print(&#8220;Adding new value:&#8221;,m)</p>
<p># Removing elements from specified index location<br />
m.pop(1)<br />
print(&#8220;Removing:&#8221;,m)</p>
<p>#sorted values<br />
m.sort()<br />
print(&#8220;sorting&#8221;,m)</p>
<p># range of values<br />
print(m[1:3]) # from second</p>
<p># Looping in list<br />
for x in m:<br />
print(x)</p>
<p># if statement in List<br />
if &#8216;Apple&#8217; in m:<br />
print(&#8220;Yes! Apple is there&#8221;)<br />
else:<br />
print(&#8220;Sorry! Apple is not in the list&#8221;)</p>
<p># Length of the list<br />
item=[&#8216;PC&#8217;, &#8216;Laptop&#8217;,&#8217;LED&#8217;,&#8217;LCD&#8217;]<br />
print(item)<br />
print(&#8220;Total no of items in list:&#8221;,len(item))</p>
<blockquote><p><span style="color: #800000;"><strong>OUTPUT:</strong></span><br />
Given list: [&#8216;Apple&#8217;, &#8216;Orange&#8217;, &#8216;Cherry&#8217;]<br />
Reverse List: [&#8216;Cherry&#8217;, &#8216;Orange&#8217;, &#8216;Apple&#8217;]<br />
Appending list: [&#8216;Cherry&#8217;, &#8216;Orange&#8217;, &#8216;Apple&#8217;, &#8216;Banana&#8217;]<br />
Copying list from one to another: [&#8216;Cherry&#8217;, &#8216;Orange&#8217;, &#8216;Apple&#8217;, &#8216;Banana&#8217;]<br />
Adding new value: [&#8216;Cherry&#8217;, &#8216;Kiwi&#8217;, &#8216;Orange&#8217;, &#8216;Apple&#8217;, &#8216;Banana&#8217;]<br />
Removing: [&#8216;Cherry&#8217;, &#8216;Orange&#8217;, &#8216;Apple&#8217;, &#8216;Banana&#8217;]<br />
sorting [&#8216;Apple&#8217;, &#8216;Banana&#8217;, &#8216;Cherry&#8217;, &#8216;Orange&#8217;]<br />
[&#8216;Banana&#8217;, &#8216;Cherry&#8217;]<br />
Apple<br />
Banana<br />
Cherry<br />
Orange<br />
Yes! Apple is there<br />
[&#8216;PC&#8217;, &#8216;Laptop&#8217;, &#8216;LED&#8217;, &#8216;LCD&#8217;]<br />
Total no of items in list: 4</p></blockquote>
<p><strong><span style="color: #0000ff;">#Tuples: A tuple is a group of items which is ordered and unchangeable.</span></strong><br />
<strong><span style="color: #0000ff;"># Tuples are writen using round brackets in python</span></strong></p>
<p>#Creating Tuple<br />
m=(&#8220;Red&#8221;, &#8220;Green&#8221;, &#8220;Blue&#8221;, &#8220;Yellow&#8221;, &#8220;Pink&#8221;)<br />
print(m)</p>
<p># accessing tuples value using index<br />
print(m[1])</p>
<p># using count method in tuples, counts no repetition of particular value in tuple<br />
tuples=(1,2,3,9,3,5,6,5,2)<br />
x=tuples.count(2)<br />
print(x)</p>
<p># Returns index of given value<br />
x=tuples.index(9)<br />
print(x)</p>
<blockquote><p><strong><span style="color: #800000;">OUTPUT:</span></strong><br />
(&#8216;Red&#8217;, &#8216;Green&#8217;, &#8216;Blue&#8217;, &#8216;Yellow&#8217;, &#8216;Pink&#8217;)<br />
Green<br />
2<br />
3</p></blockquote>
<p><strong><span style="color: #0000ff;"># A set is a collection of items which is unordered and unindexed.</span></strong><br />
<strong><span style="color: #0000ff;"># sets are written with curly brackets in python.</span></strong></p>
<p># creating sets in python<br />
mset={&#8220;Java&#8221;, &#8220;Python&#8221;, &#8220;CPP&#8221;}<br />
print(mset)</p>
<p># accessing set values using loop<br />
for x in mset:<br />
print(x)</p>
<p>#adding values to sets<br />
mset.add(&#8220;PHP&#8221;)<br />
print(mset)</p>
<p># Removing specified items from sets<br />
mset.discard(&#8220;CPP&#8221;)<br />
print(mset)</p>
<blockquote><p><strong><span style="color: #800000;">OUTPUT:</span></strong><br />
{&#8216;CPP&#8217;, &#8216;Python&#8217;, &#8216;Java&#8217;}<br />
CPP<br />
Python<br />
Java<br />
{&#8216;CPP&#8217;, &#8216;Python&#8217;, &#8216;PHP&#8217;, &#8216;Java&#8217;}<br />
{&#8216;Python&#8217;, &#8216;PHP&#8217;, &#8216;Java&#8217;}</p></blockquote>
<p><strong><span style="color: #0000ff;"># A dictionary is a collection or group of items and are unordered,</span></strong><br />
<strong><span style="color: #0000ff;"># and changeable and indexed.</span></strong><br />
<strong><span style="color: #0000ff;">#In Python dictionaries are written with curly brackets, and they have keys and values.</span></strong></p>
<p>#creating dictionary in python<br />
dict={<br />
&#8220;OS&#8221;: &#8220;Windows&#8221;,<br />
&#8220;Processor&#8221;: &#8220;Corei3&#8221;,<br />
&#8220;Year of Launch&#8221;:2010}</p>
<p>print(dict)</p>
<p># Accessing values based on their key<br />
x=dict[&#8220;OS&#8221;]<br />
print(x)</p>
<p>x=dict[&#8220;Processor&#8221;]<br />
print(x)</p>
<p>x=dict[&#8220;Year of Launch&#8221;]<br />
print(x)</p>
<p># Accessing all values from dictionary<br />
y=dict.values()<br />
print(y)</p>
<blockquote><p><strong><span style="color: #800000;">OUTPUT:</span></strong><br />
{&#8216;Year of Launch&#8217;: 2010, &#8216;OS&#8217;: &#8216;Windows&#8217;, &#8216;Processor&#8217;: &#8216;Corei3&#8217;}<br />
Windows<br />
Corei3<br />
2010<br />
dict_values([2010, &#8216;Windows&#8217;, &#8216;Corei3&#8217;])</p></blockquote>
<p><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fmitindia.in%2Fcollections-in-python%2F&amp;linkname=Collections%20in%20Python" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fmitindia.in%2Fcollections-in-python%2F&amp;linkname=Collections%20in%20Python" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fmitindia.in%2Fcollections-in-python%2F&#038;title=Collections%20in%20Python" data-a2a-url="https://mitindia.in/collections-in-python/" data-a2a-title="Collections in Python"><img src="https://static.addtoany.com/buttons/favicon.png" alt="Share"></a></p><p>The post <a href="https://mitindia.in/collections-in-python/">Collections in Python</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
