blob: 7e5a3eeb3d926e8ba2e3bfcb6d83559fd827659f [file] [log] [blame]
# insert
foo = ['a', 'b']
foo.insert(0, 'c')
assert_eq(foo, ['c', 'a', 'b'])
foo.insert(1, 'd')
assert_eq(foo, ['c', 'd', 'a', 'b'])
foo.insert(4, 'e')
assert_eq(foo, ['c', 'd', 'a', 'b', 'e'])
foo.insert(-10, 'f')
assert_eq(foo, ['f', 'c', 'd', 'a', 'b', 'e'])
foo.insert(10, 'g')
assert_eq(foo, ['f', 'c', 'd', 'a', 'b', 'e', 'g'])
# check that list() returns new mutable object
a = list()
b = list()
a.insert(0, 1)
assert_eq(a, [1])
assert_eq(b, [])
---
(1, 2).insert(3) ### type 'tuple' has no method insert\(\)
---
# append
foo = ['a', 'b']
foo.append('c')
assert_eq(foo, ['a', 'b', 'c'])
foo.append('d')
assert_eq(foo, ['a', 'b', 'c', 'd'])
---
(1, 2).append(3) ### type 'tuple' has no method append\(\)
---
# extend
foo = ['a', 'b']
foo.extend(['c', 'd'])
foo.extend(('e', 'f'))
assert_eq(foo, ['a', 'b', 'c', 'd', 'e', 'f'])
---
(1, 2).extend([3, 4]) ### type 'tuple' has no method extend()
---
[1, 2].extend(3) ### expected value of type 'sequence' for parameter 'items'
# remove
foo = ['a', 'b', 'c', 'b']
foo.remove('b')
assert_eq(foo, ['a', 'c', 'b'])
foo.remove('c')
assert_eq(foo, ['a', 'b'])
foo.remove('a')
assert_eq(foo, ['b'])
foo.remove('b')
assert_eq(foo, [])
---
(1, 2).remove(3) ### type 'tuple' has no method remove\(\)
---
[1, 2].remove(3) ### item 3 not found in list
---
# pop
li1 = [2, 3, 4]
assert_eq(li1.pop(), 4)
assert_eq(li1, [2, 3])
li2 = [2, 3, 4]
assert_eq(li2.pop(-2), 3)
assert_eq(li2, [2, 4])
li3 = [2, 3, 4]
assert_eq(li3.pop(1), 3)
assert_eq(li3, [2, 4])
---
[1, 2].pop(3) ### index out of range (index is 3, but sequence has 2 elements)
---
(1, 2).pop() ### type 'tuple' has no method pop()