Python Exercise Example 74
**Problem:** List sorting and concatenation.
**Program Analysis:** For sorting you can use the sort() method; for concatenation you can use the + operator or the extend() 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
a
Concatenate lists a and b
a
b
Concatenate lists a and b
a
.
extend
(
b
)
a
[1, 2, 3]
[1, 2, 3, 3, 4, 5]
[1, 2, 3, 3, 4, 5]
Python 100 Examples