<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Tuples_and_Lists</id>
	<title>Tuples and Lists - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Tuples_and_Lists"/>
	<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Tuples_and_Lists&amp;action=history"/>
	<updated>2026-05-14T01:24:41Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://training-course-material.com/index.php?title=Tuples_and_Lists&amp;diff=9204&amp;oldid=prev</id>
		<title>Kristian Rother: /* Creating lists from other lists */</title>
		<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Tuples_and_Lists&amp;diff=9204&amp;oldid=prev"/>
		<updated>2013-02-05T20:07:20Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Creating lists from other lists&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Cat|Python Commands}}&lt;br /&gt;
{{Python Links}}&lt;br /&gt;
&lt;br /&gt;
== Creating tuples ==&lt;br /&gt;
A tuple is a sequence of elements that cannot be modified. They are useful to group elements of different type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
t = (&amp;#039;bananas&amp;#039;,&amp;#039;200g&amp;#039;,0.55)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Creating lists ==&lt;br /&gt;
A list is a sequence of elements that can be modified. In many cases, all elements of a list will have the same type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
l = [&amp;#039;apples&amp;#039;,&lt;br /&gt;
&amp;#039;bananas&amp;#039;,&lt;br /&gt;
&amp;#039;oranges&amp;#039;]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Accessing elements of lists and tuples ==&lt;br /&gt;
Using square brackets, any element of a list and tuple can be accessed. The first character has the index 0.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
l = [1,2,3,4]&lt;br /&gt;
print l[0] # first&lt;br /&gt;
print l[3] # last&lt;br /&gt;
print l[-1] # last&lt;br /&gt;
l[0] = &amp;#039;kiwi&amp;#039; # assigning an element&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Creating lists from other lists ==&lt;br /&gt;
Lists can be sliced by applying square bracketsin the same way as substrings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
l = [0,1,2,3,4,5]&lt;br /&gt;
print l[1:3] # [1,2]&lt;br /&gt;
print l[0:2] # [0,1]&lt;br /&gt;
print l[:3] # [0,1,2]&lt;br /&gt;
print l[-2:] # [4,5]&lt;br /&gt;
m = l[:] # creates a copy!&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== List functions =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
l[0] = &amp;#039;kiwi&amp;#039; # assigning an element&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Adding elements to a list: =====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
l.append(5) # adds at the end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Removing elements from a list: =====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
l.remove(3)&lt;br /&gt;
&lt;br /&gt;
l.pop() # removes last element&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Sorting a list =====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
l.sort()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Count elements: =====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
l.count(3)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kristian Rother</name></author>
	</entry>
</feed>