List: more about python lists


Deleting an item in a list:

>>> aList = ['one', 'two','three', 'four','five','six', 'seven']
>>> del aList[3]
>>> aList
['one', 'two', 'three', 'five', 'six', 'seven'] # 'four' is missing
>>> 
or 
>>> aList.remove('two')
>>> aList
['one', 'three', 'five', 'six', 'seven']  # 'two' is missing
>>> 

List of lists:

>>> twoLists = [['biology','chemistry','physics','horticulture', 'english','math','physed','spanish'],['period 1','period 2','period 3', 'period 4','period 5','period 6','period 7', 'period 8']]
>>> twoLists[0][0]
'biology'
>>> twoLists[1][0]
'period 1'
>>> 

Changing the text to lower case or upper case.

>>> aString1 = 'Hello, World'
>>> aString2 = aString1.lower()
>>> aString2
'hello, world'
>>> aString3 = aString1.upper()
>>> aString3
'HELLO, WORLD'
>>> 


Classwork:
Write a program, WordList.py with the following:
1. Create a list with 10 items and show how to delete a given item in the list.
2. Use the same list to delete the third item in the list.
3. Create a new list with two elements. Each element is also a list with nine elements.
4. Use two for loops to display the elements of this list.
Each element of this list should be displayed in a row of its own.

   biology chemistry physics horticulture english math physed spanish 
   period 1 period 2 period 3 period 4 period 5 period 6 period 7 period 8 
   

5. Use two for loops to display the elements in the list side by side:

biology      period 1
chemistry    period 2
physics      period 3
horticulture period 4
english      period 5
mathematica  period 6
physed       period 7
spanish      period 8

Here is code for string format

>>> print("%15s %14s" % ("hello","goodbye"))
          hello        goodbye

Clue for twoLists second part:

for i in range(len(twoLists[0])):
    for j in range(len(twoLists)):
        print( '\t',twoLists[?][?],' ',end='')
    print()

6. Print a sentence in lower case and then in upper case.

Classwork: