crazyList1 = [1, True, [ 'sublist', 42], 'A' ] crazyList2 = [2, False, [ 'sublist', 42], 'B' ]Draw how crazyList1 and crazyList2 are stored in memory
crazyList1 = [1, True, ['sublist', 42], 'A' ] crazyList2 = [2, False, ['sublist', 42], 'B' ] print( crazyList1[0] ) print( crazyList1[2] ) print( id( crazyList1 ) ) print( crazyList1 is crazyList2 ) print( crazyList1 == crazyList2 ) print( crazyList1[2] is crazyList2[2] ) print( crazyList1[2] == crazyList2[2] ) crazyList3 = crazyList1 print( id( crazyList3 ) ) print( crazyList1 is crazyList3 ) print( crazyList1 == crazyList3 ) crazyList4 = list( crazyList1 ) print( id( crazyList4 ) ) print( crazyList1 is crazyList4 ) print( crazyList1 == crazyList4 )
['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] * 52
[ ] * 52
nums = [] nums.append( 42 ) nums.extend( 1 ) nums.extend( [5, 7, 9, 1] ) nums.insert( 2, 3 ) nums.remove( 7 ) print( nums.pop() ) print( nums.pop( 1 ) ) nums.sort() nums.reverse() print( nums.index( 3 ) ) print( nums.count( 42 ) )
def exclamationCount( listOfStrings ): counts = [ ] for string in listOfStrings: numExclamations = 0 for ch in string: if ch == '!': numExclamations += 1 counts.append( numExclamations ) return counts
def exclamationCount( listOfStrings ): counts = [ ] for string in listOfStrings: numExclamations = 0 for ch in string: if ch == '!': numExclamations += 1 counts.append( numExclamations ) return counts
def exclamationCount( listOfStrings ): counts = [ ] for string in listOfStrings: numExclamations = 0 for ch in string: if ch == '!': numExclamations += 1 counts.append( numExclamations ) return counts
def exclamationCount( listOfStrings ): counts = [ ] for string in listOfStrings: numExclamations = 0 for ch in string: if ch == '!': numExclamations += 1 counts.append( numExclamations ) return counts
rainfall = [0.09, 0, 0, 0, 0, 0.81, 0, 0, 0, 0, 1.19, 0.08, 0, 0, 0, 0, 0, 0.22, 0.08, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.77, 0.05, 0] # inchesHow short can you make the code (using built-in list functions)?
assignments = [88, 94, 81, 92, 80, 82, 84, 74, 83, 93]
grades = [81.9, 76.8, 77.4, 99.4, 66.2, 67.7, 69.7, 85.7, 92, 69.3, 71.3, 73.9]
2 was rolled 28025 times 3 was rolled 55530 times 4 was rolled 83003 times 5 was rolled 111318 times 6 was rolled 138968 times 7 was rolled 166302 times 8 was rolled 138591 times 9 was rolled 111151 times 10 was rolled 83449 times 11 was rolled 55804 times 12 was rolled 27859 timesClick HERE for a hint.
import random def main(): # Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec daysPerMonth = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] rainfall = [] month = 0 for days in daysPerMonth: rainfall.append( [] ) for i in range( days ): rainfall[month].append( round(random.random() * 3.0, 1) ) month += 1 print('rainfall = [') for month in rainfall: print( ' ' + str(month) + ',' ) print(']') if __name__ == '__main__': main()