Python Exercise Example 74
Problem:List sorting and concatenation.
Program analysis:Sorting can usesort()method, and concatenation can use+sign orextend()method.
Program source code:
Example
#!/usr/bin/python
# -*- coding: UTF-8 -*-
if __name__ == '__main__':
a = [1,3,2]
b = [3,4,5]
a.sort() # Sort list a
print a
# Concatenate list a and b
print a+b
# Concatenate list a and b
a.extend(b)
print a
[1, 2, 3] [1, 2, 3, 3, 4, 5] [1, 2, 3, 3, 4, 5]Other Extensions
Python 100 Examples