Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Exercise Example 74

Python Exercise Example 74

Python 100 Examples Python 100 Examples

**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

print

a

Concatenate lists a and b

print

a

b

Concatenate lists a and b

a

.

extend

(

b

)

print

a


[1, 2, 3]
[1, 2, 3, 3, 4, 5]
[1, 2, 3, 3, 4, 5]

Python 100 Examples Python 100 Examples