<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Srinivasu Rankireddy on Medium]]></title>
        <description><![CDATA[Stories by Srinivasu Rankireddy on Medium]]></description>
        <link>https://medium.com/@srinivasurankireddy?source=rss-488e2a034d77------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wUyl8M4Gp6Vjb4IQO4XEsg.jpeg</url>
            <title>Stories by Srinivasu Rankireddy on Medium</title>
            <link>https://medium.com/@srinivasurankireddy?source=rss-488e2a034d77------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 13:53:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@srinivasurankireddy/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Python List Slicing and Examples]]></title>
            <link>https://medium.com/@srinivasurankireddy/python-list-slicing-and-examples-9c8384148f8a?source=rss-488e2a034d77------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c8384148f8a</guid>
            <category><![CDATA[python-web-developer]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Srinivasu Rankireddy]]></dc:creator>
            <pubDate>Sat, 30 Dec 2017 16:36:50 GMT</pubDate>
            <atom:updated>2017-12-30T16:36:50.915Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python List Slicing!</h3><p>Hey I’m writing my first blog about <strong>Python Sequence Slicing</strong> with few examples. Python slicing is the best approach for playing with sequences in python without writing more complex code for accessing the items in sequences.</p><p>In python has builtin sequences. they are <strong>List, Byte, Str</strong>.</p><ul><li>Python Slicing Gives you making sequences into small small pieces.</li><li>Python Slicing Gives you accessing the subset of items from sequence.</li><li>You can slice the items in builtin sequence types list, byte, str.</li><li>Slicing can be extended to any python abstract data type which implements the <strong>__getitem__</strong>, <strong>__setitem__</strong> methods.</li><li>Syntax for Slicing is: <strong>sequence_items[start_index:end_index]</strong>. Here <strong>start_index</strong> is starting position for subset and it is Inclusive and <strong>end_index </strong>is last position for subset and it is Exclusive.</li></ul><h4>Few examples for List slicing with Explanation</h4><blockquote><em>Defined an input data variable as data with length of 7.</em></blockquote><pre>data = [1, 4, 3, 5, 2, 7, 5]</pre><blockquote><em>Accessing the first 3 elements from list using Slicing:</em></blockquote><pre>first_three_elements = <strong>data</strong>[0:3]</pre><blockquote><em>Accessing the subset of list from first element.</em></blockquote><pre>&gt; data[:3]<br>  [1, 4, 3]</pre><blockquote><em>Accessing subset of list . that subset will be started from 4th position to end of the list.</em></blockquote><pre>&gt; data[4:]<br>  [2, 7, 5]</pre><blockquote><em>Accessing subset of list.</em></blockquote><pre>&gt; data[2:5]<br>  [3, 5, 2] </pre><h4>Python Negative Indexing for Sequences</h4><p>Python gives you an option to accessing the sequences from end using the negative indexing.</p><blockquote><em>Suppose if you want to access the last element of the list then</em></blockquote><pre>&gt; data[-1]<br>  5</pre><blockquote><em>With out negative indexing, accessing the last element of list as follows.</em></blockquote><pre>data = [1,4,3,5,2,7]<br>length = len(data)<br>last_element = data[length-1]<br>=&gt; 7</pre><p>If you are using negative indexing then there is no need of the length of the list to accessing the last element.</p><blockquote><em>If you want to access the last but one element of the list then</em></blockquote><pre>&gt; data[-2]<br>  7</pre><blockquote><em>If we want to access the last 3 elements the you can use the negative indexes.</em></blockquote><pre>&gt; data[-3:]<br>  [2, 7, 5]</pre><blockquote><em>If we want to access the subset of list which is started from 2nd element and ended with 3rd element from last then you can write as follows.</em></blockquote><pre>&gt; data[1:-2]<br>=&gt; [4, 3, 5, 2]</pre><blockquote><em>Subset of list using negative indexing.</em></blockquote><pre>&gt; data[-3:-1]<br>=&gt; [2, 7] </pre><blockquote><em>Reversing a complete list using Slicing:</em></blockquote><pre>&gt; data[::-1]<br>  [5, 7, 2, 5, 3, 4, 1]</pre><blockquote><em>If you are not given any start and end Index values then it will print original list.</em></blockquote><pre>&gt; data[:]<br>  [1, 4, 3, 5, 2, 7, 5]</pre><h4>Python Slicing with Step</h4><p>Well, People may think about step in sequence slicing. What is this step and how it helps to playing with lists.</p><p>Developers may familiar with step in range function. when we are giving the step value in range function then next index will be jumping to the those many positions.</p><pre>&gt; for item in range(0, 10, 3):<br>&gt; print(item)<br>0<br>3<br>6<br>9</pre><p>Same will be applicable here but syntax will change.</p><p>Syntax is</p><p>data_list[start_position:endposition:stepvalue]</p><p>We can get the all even indexed elements from sequence using following syntax.</p><p>data_list[::2]</p><p>We can get the all odd indexed elements from sequence using following syntax.</p><p>data_list[1::2]</p><p><strong>We can use the negative values for step value. Consider the following.</strong></p><p>We can reverse a sequence using following syntax. Here -1 is the negative value for step and it will reverse the entire list. It works well for all types of sequences except Unicode strings(Few Cases).</p><p>data_list[::-1]</p><p>Extract even position elements form last:</p><p>data_list[::-2]</p><p>Thank you for reading my first blog post. If you like, then give a clap.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c8384148f8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>