Python implements a simple list bubble sorting and reverse list operation example

  • 2021-07-13 05:36:33
  • OfStack

In this paper, the example shows that Python implements simple list bubble sorting and reverse list operation. Share it for your reference, as follows:

# -*- coding:utf-8 -*-
#! python2
print a
def sortAndAddNew(a):
  for i in range(l):
    for j in range(l):
      if (a[i]>a[j]):
  for k in range(len(a)):
  return b
print b
print list(reversed(b))

Run results:

[3, 4, 6, 2, 1]
[6, 4, 3, 2, 1]
[1, 2, 3, 4, 6]

PS: Here we recommend another demonstration tool about sorting for your reference:

Online animation demonstrates insert/select/bubble/merge/hill/quick sort algorithm process tool:

More readers interested in Python can check the topics of this site: "Python Data Structure and Algorithm Tutorial", "Python List (list) Operation Skills Summary", "Python Coding Operation Skills Summary", "Python Function Use Skills Summary", "Python String Operation Skills Summary" and "Python Introduction and Advanced Classic Tutorial"

I hope this article is helpful to everyone's Python programming.

Related articles: