In the following code, this is a simple algorithm written to sort items. The question is, how do strings compare inside and how does the interpreter know that these strings should be placed after integers
a=[22, 66, 54, 11, 16, 2, 5, 'b', 'a', 3, 2, 1] >>> for i in range(len(a)-1): ... for j in range(len(a)-i-1): ... if a[j] > a[j+1]: ... a[j],a[j+1]=a[j+1],a[j] ... >>> print a [1, 2, 2, 3, 5, 11, 16, 22, 54, 66, 'a', 'b']
source share