<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Python &amp; Scratch Bubble sorts for KS3</title>
	<atom:link href="http://www.suppertime.co.uk/blogmywiki/2015/10/python-bubble-sort-for-ks3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.suppertime.co.uk/blogmywiki/2015/10/python-bubble-sort-for-ks3/</link>
	<description>reading, writing, coding, making</description>
	<lastBuildDate>Tue, 24 Oct 2023 13:43:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<item>
		<title>By: marc</title>
		<link>http://www.suppertime.co.uk/blogmywiki/2015/10/python-bubble-sort-for-ks3/#comment-86081</link>
		<dc:creator>marc</dc:creator>
		<pubDate>Wed, 28 Oct 2015 09:50:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.suppertime.co.uk/blogmywiki/?p=2201#comment-86081</guid>
		<description>Yes you do need to do a test there but you don&#039;t need to keep count. So you can just set it to 1 as you say as a flag if there is a swap but as that is then acting as a boolean it suggests it isn&#039;t needed at all.  Indeed, it isn&#039;t - just set &quot;sorted&quot; to true after the &quot;while&quot; statement &amp; then set it to false if you do a swap. then delete the last &quot;if&quot; as no longer needed.

ie change the while loop to:
while not sorted:
    sorted = True                                #instead of swaps = 0
    for i in range(len(numberList)-1):
        if numberList[i] &gt; numberList[i+1]:
            temp = numberList[i]
            numberList[i] = numberList[i+1]
            numberList[i+1] = temp
            Sorted = False                     #if make a swap then sorted is false &amp; so while loops again
            # no second if as if there has not been a swap then sorted has not changed from true but if there has then it is false

So you save a variable and save an increment function. You still probably set Sorted to false several times but avoiding that takes more code &amp; is less efficient.

Bonus point to the kid who notices than you don&#039;t need to calculate (len(numberList)-1) every time in the &quot;for&quot; statement &amp; so quicker to set a variable to that value before entering the while loop.

Wow this is so much more fun than work....


marc</description>
		<content:encoded><![CDATA[<p>Yes you do need to do a test there but you don&#8217;t need to keep count. So you can just set it to 1 as you say as a flag if there is a swap but as that is then acting as a boolean it suggests it isn&#8217;t needed at all.  Indeed, it isn&#8217;t &#8211; just set &#8220;sorted&#8221; to true after the &#8220;while&#8221; statement &amp; then set it to false if you do a swap. then delete the last &#8220;if&#8221; as no longer needed.</p>
<p>ie change the while loop to:<br />
while not sorted:<br />
    sorted = True                                #instead of swaps = 0<br />
    for i in range(len(numberList)-1):<br />
        if numberList[i] &gt; numberList[i+1]:<br />
            temp = numberList[i]<br />
            numberList[i] = numberList[i+1]<br />
            numberList[i+1] = temp<br />
            Sorted = False                     #if make a swap then sorted is false &amp; so while loops again<br />
            # no second if as if there has not been a swap then sorted has not changed from true but if there has then it is false</p>
<p>So you save a variable and save an increment function. You still probably set Sorted to false several times but avoiding that takes more code &amp; is less efficient.</p>
<p>Bonus point to the kid who notices than you don&#8217;t need to calculate (len(numberList)-1) every time in the &#8220;for&#8221; statement &amp; so quicker to set a variable to that value before entering the while loop.</p>
<p>Wow this is so much more fun than work&#8230;.</p>
<p>marc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: blogmywiki</title>
		<link>http://www.suppertime.co.uk/blogmywiki/2015/10/python-bubble-sort-for-ks3/#comment-86046</link>
		<dc:creator>blogmywiki</dc:creator>
		<pubDate>Tue, 27 Oct 2015 13:30:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.suppertime.co.uk/blogmywiki/?p=2201#comment-86046</guid>
		<description>Hi Marc. Thanks for commenting. You may well have a point! I think it&#039;s needed, or at least a &#039;swaps made in this run&#039; flag is needed, as some pairs may not need swapping in a run through the list, and you don&#039;t want it to stop just because two numbers are in the right order (no swap). I need to have a think and a play!</description>
		<content:encoded><![CDATA[<p>Hi Marc. Thanks for commenting. You may well have a point! I think it&#8217;s needed, or at least a &#8216;swaps made in this run&#8217; flag is needed, as some pairs may not need swapping in a run through the list, and you don&#8217;t want it to stop just because two numbers are in the right order (no swap). I need to have a think and a play!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: marc</title>
		<link>http://www.suppertime.co.uk/blogmywiki/2015/10/python-bubble-sort-for-ks3/#comment-86032</link>
		<dc:creator>marc</dc:creator>
		<pubDate>Tue, 27 Oct 2015 10:12:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.suppertime.co.uk/blogmywiki/?p=2201#comment-86032</guid>
		<description>Why the swaps variable? It seems only to be used to determine whether to change sorted to true or not.  Why not do that directly? i.e. after &quot;if numberList[i] &gt; numberList[i+1]:&quot; , just put &quot;sorted = True&quot;?


Keep up the good work!</description>
		<content:encoded><![CDATA[<p>Why the swaps variable? It seems only to be used to determine whether to change sorted to true or not.  Why not do that directly? i.e. after &#8220;if numberList[i] &gt; numberList[i+1]:&#8221; , just put &#8220;sorted = True&#8221;?</p>
<p>Keep up the good work!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
