Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 3

21 bytes added, 07:34, 3 June 2017
PART 1 - Navigating Items in Lists
list2 = [ 'uli101', 'ops235', 'ops335', 'ops435', 'ops535', 'ops635' ]
list3 = [ 'uli101', 1, 'ops235', 2, 'ops335', 3, 'ops435', 4, 'ops535', 5, 'ops635', 6 ]
</source>List are constructed similar to arrays. The best way to get individual '''elements''' from a list is using the list '''index'''. <br>The index is a number starting from 0 to (number_of_items - 1), the list index starts counting at 0.<br><br>
:#Issue the following in the ipython shell to obtain stored data:<source>
list1[0] # First item element in list1list2[1] # Second item element in list2list3[-1] # Last item element in list3
</source>
:#Issue the following to provide ranges of items in a list: <source>
</source>
:#To access a list inside another list, a second index is needed. Spend some time trying out the syntax and try and navigate to a specific spot in the list.<source>
list4[0][0] # First item element in first listlist4[0][-1] # Last item element in first listlist4[2][0:2] # First two items elements in third list
</source>
:#Using different items from different lists to create new lists.<source>
13,420
edits