Class 10 – Wednesday, September 15

Listing

Lest we go forward — Without knowing about lists — We would be wanting


Look both ways


Agenda


Important survey


For the fun of it


Alert


To do list


Downloads


Program wowzers.py

Enter your favorite color: teal

Enter some names: willy evander aurelius ann

color = teal

names = ['willy', 'evander', 'aurelius', 'ann' ]

numbers = [12, 7, -11, -12, 59]

T

E

A

L

Willy

Evander

Aurelius

Ann

-12

-7

11

12

-59

t e a l

['willy', 'evander', 'aurelius', 'ann' ]

[5, 7, 8, 3]

length of longest name: 8

first alphabetically = ann



Accumulation


Program on_average.py

  • Compute length of the current word of interest.
  • Add that length to running total of the word lengths.

Enter text: over the hill and through the dale

words = ['over', 'the', 'hill', 'and', 'through', 'the', 'dale']

Average word length: 4.0

Enter text: row row row your boat

words = ['row', 'row', 'row', 'your', 'boat']

Average word length: 3.4



List accumulation — program all_int.py

  • Get integer representation of the string.
  • Add integer to the list accumulation
  • Print accumulation.

Enter integers: 3 1 4 1 5 9

nbr_strings: ['3', '1', '4', '1', '5', '9']

numbers: [3]

numbers: [3, 1]

numbers: [3, 1, 4]

numbers: [3, 1, 4, 1]

numbers: [3, 1, 4, 1, 5]

numbers: [3, 1, 4, 1, 5, 9]


Enter integers: 58 2 37 16 99 1 9 23

nbr_strings: ['58', '2', '37', '16', '99', '1', '9', '23']

numbers: [58]

numbers: [58, 2]

numbers: [58, 2, 37]

numbers: [58, 2, 37, 16]

numbers: [58, 2, 37, 16, 99]

numbers: [58, 2, 37, 16, 99, 1]

numbers: [58, 2, 37, 16, 99, 1, 9]

numbers: [58, 2, 37, 16, 99, 1, 9, 23]

# get input

reply = input( 'Enter integers: ' )

print()

# split reply into list of numeric strings

nbr_strings = reply.split()

# see what we got

print( 'nbr_strings:', nbr_strings )

print()

# convert numeric text into list of numbers

# begin with setting up the accumulator

numbers = [] # initialize holder to prepare for adding elements

# process the strings of nbr_strings one-by-one

for ns in nbr_strings :

  # process the current numeric string

  nbr = int( ns ) # get numeric equivalent of ns

  numbers.append( nbr ) # add equivalent to list of numbers

  print( 'numbers:', numbers ) # print the updated list of numbers



Host of Flying Monkey Manor

scary person



Willy Mays

Willy Mays button



Marcus Aurelius

Metropolitan Marcus Aurelius Roman 2C AD 2



Evander of Pallantium

Evander of Greek mythology