Class 10 – Wednesday, February 24

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


Lists


Program list_support.py

s = "we are in it together"

values = [ ]

stuff = [ 'abc', 1112, 2.71, ]

digits = [ 3, 1, 4, 1, 5, 9, 2, 6 ]

words = s.split()

vlen = len( values )

slen = len( stuff )

dlen = len( digits )

wlen = len( words )

print( "size of", values, "=", vlen )

print( "size of", stuff, "=", slen )

print( "size of", digits, "=", dlen )

print( "size of", words, "=", wlen )

dmax = max( digits )

dmin = min( digits )

wmax = max( words )

wmin = min( words )

print( "max of", digits, "=", dmax )

print( "min of", digits, "=", dmin )

print( "max of", words, "=", wmax )

print( "min of", words, "=", wmin )

size of [] = 0

size of ['abc', 1112, 2.71] = 3

size of [3, 1, 4, 1, 5, 9, 2, 6] = 8

size of ['we', 'are', 'in', 'it', 'together'] = 5

max of [3, 1, 4, 1, 5, 9, 2, 6] = 9

min of [3, 1, 4, 1, 5, 9, 2, 6] = 1

max of ['we', 'are', 'in', 'it', 'together'] = we

min of ['we', 'are', 'in', 'it', 'together'] = are



Program list_building.py

values = [ ]

values.append( "u" )

values.append( "v" )

values.append( "a" )

values.append( "!" )

values.append( " " )

values.append( "u" )

values.append( "v" )

values.append( "a" )

values.append( "!" )

print( "values =", values )

ints = []

for i in range( 0, 10 ) :

  ints.append( i )

print( "ints =", ints

values = ['u', 'v', 'a', '!', ' ', 'u', 'v', 'a', '!']

ints = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]



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



Numeric list paradigm — program summing.py

reply = input( 'Enter a list of numbers: ' )

slist = reply.split()

nlist = []

for s in slist :

  nbr = int( s )

  nlist.append( nbr )

# by accumulation get the sum of the numbers

total = 0

for nbr in nlist :

  total = total + nbr

# print summation

print( "sum(", nlist, "):", total )

Enter a list of numbers: 3 1 4 1 5 9

sum( [3, 1, 4, 1, 5, 9] ): 23

Enter a list of numbers: 58 2 37 16 99 1 9 23

sum( [58, 2, 37, 16, 99, 1, 9, 23] ): 245



Chrestomathics — program secret_decoder.py

'abcdefghijklmnopqrstuvwxyz-'

and the indices are

[ 4, 8, 26, 4, 8, 26, 14 ]

'ei-ei-o'

Because s[ 4 ] equals 'e';   s[ 8 ] equals 'i';   s[ 14 ]; equals 'o';   and s[ 26 ] equals '-'.

Enter code phrase: computer

Code phrase: computer

Enter indices: 3 6 5

Indices: [3, 6, 5]

Hidden message: pet


Enter code phrase: gosh look what the cat is up to now

Code phrasee: gosh look what the cat is up to now

Enter indices: 24 5 17 17 27 23 32 0

Indices: [24, 5, 17, 17, 27, 23, 32, 0]

Hidden message: sleeping


Enter code phrase: ‐abcdefghijklmnopqrstuvwxyz‐

Code phrase: ‐abcdefghijklmnopqrstuvwxyz-

Enter indices: 12 15 22 5 27 9 19 0 1 12 12 27 14 5 5 4

Indices: [12, 15, 22, 5, 27, 9, 19, 0, 1, 12, 12, 27, 14, 5, 5, 4]

Hidden message: love‐is‐all‐need



Hoos got your back — food insecurity


Coney Island Cyclone roller coaster

Coney Island Cyclone



Willy Mays

Willy Mays button



Marcus Aurelius

Metropolitan Marcus Aurelius Roman 2C AD 2



Evander of Pallantium

Evander of Greek mythology

 


  🦆 © 2022 Jim Cohoon   Resources from previous semesters are available.