## aVar++ 14

Hi guys,

I got this from my teacher and im really confused. could anyone point me in the right direction?

Thanks

What does it do?

This time I'm looking for an overall summary, in one sentence, with the word "by" in the middle:

``````"This function ..........., by ................ ."
``````

This function takes a list of numbers as an argument, and returns a list of numbers.
To help you figure it out, cut out 5 or 6 pieces of paper, write some numbers on them, put them on a table, and run the algorithm yourself.

``````define MyFunction (list):
for OuterForLoopCounter in 1 to listlength-1:
for InnerForLoopCounter in 1 to listlength-1:
if list[InnerForLoopCounter] is greater than list[InnerForLoopCounter+1]:
swap list[item] and list[item+1]
return (list)
``````

## pyTony 888

Look articles on sorting algorithm based on swapping adjacent items.

## Lucaci Andrew 140

Let me give you a head start:

``````def myfunc(l):
for i in range (1, len(l)-1):
for j in range (1, len(l)-1):
``````

for

``````define MyFunction (list):
for OuterForLoopCounter in 1 to listlength-1:
for InnerForLoopCounter in 1 to listlength-1:
``````

now, how about implementing the rest:

`````` if list[InnerForLoopCounter] is greater than list[InnerForLoopCounter+1]:
swap list[item] and list[item+1]
return (list)
``````

## Lucaci Andrew 140

Also, for the swaping part, Python allowes this too:

``````>>> i, j = 1, 2
>>> i
1
>>> j
2
>>>
``````

so swaping is really easy.