APPENDIX: Lists

a_list.append( [4, 5] ) my_list = list( range(10) ) my_list + [10, 11, 12] our_list.extend( range(5,11) ) alpha.insert(1,’b’) new_list = […]

Read More
Comments Off on APPENDIX: Lists

Slice with Steps

[Start:Stop:Step] >>> my_list = list(range(20)) >>> my_list [0,1,2,3, … , 19] >>> my_list[::2] [0,2,4,6,8, … ,18] >>> my_list[2::2] [2,4,6,8, … […]

Read More
Comments Off on Slice with Steps

Slices

Slicing Strings >>> my_string = “Hello there” >>> my_string[1:5] ‘ello’ >>> my_string[2] ‘l’ Slicing Lists >>> my_list = list(range(1,6)) >>> my_list […]

Read More
Comments Off on Slices

Pop

pop( index ) >>> names = [“Bashar”, “Ahmad”, “Mustafa”] >>> name_1 = names.pop() >>> name_1 ‘Mustafa’ >>> names [“Bashar”, “Ahmad”] […]

Read More
Comments Off on Pop

Removing List Items

Item Index >>> a_list = list(‘abzcd’) >>> a_list.index(‘z’) 2 Delete by index List Items Deletion >>> del a_list[2] >>> a_list [‘a’, […]

Read More
Comments Off on Removing List Items

Lists Redux

Combining Lists append( list ) >>> a_list = [1, 2, 3] >>> a_list.append( [4, 5] ) >>> a_list [1, 2, […]

Read More
Comments Off on Lists Redux