Chapter 7
Section 7.2 Initialization
|
|
51600 |
plist = [] |
51601 |
plist = ["spam", "eggs", "vikings"] |
51192 |
plist = [10,20,30,40,50,60,70,80,90,100] |
51193 |
tax_rates = [0.10, 0.15, 0.21, 0.28, 0.31] |
51194 |
denominations = [1,5,10,25,50,100] |
Section 7.2 Indexing | |
51280 |
for i in range(len(list1)-1) : if list1[i] in list1[i+1:] : has_dups = True break else : has_dups = False |
51203 |
plist[-1] += 5 |
51201 |
salary_steps[-1] = 160000 |
51195 |
plist[0] |
51196 |
plist[-1] |
51197 |
x=plist[-2] |
51199 |
plist[0] = 3 |
51200 |
salary_steps[0] = 30000 |
51202 |
plist[0]+= 10 |
51204 |
plist[k] = 15 |
51205 |
plist[-1] = -1 |
51206 |
plist[k+1] = 9 |
51207 |
plist[k-1] = 22 |
51208 |
plist[j] = 2 * plist[j+1] |
51209 |
play_list[0] = 2*play_list[-1] |
Section 7.2 Length | |
51611 |
plist1 + plist2 |
51612 |
plist3 = plist1 + plist2 |
51602 |
len(play_list) |
51211 |
a[len(a) - i - 1] |
Section 7.3 | |
51613 |
play_list[0:5] |
51614 |
play_list[k:j+1] |
51615 |
play_list[k:j] |
51616 |
play_list[0:3] = ["spam", "eggs", "vikings"] |
51617 |
L1[5:9] = L2 |
51618 |
lesser_offenders = worst_offenders[5:] |
51619 |
plist2 = plist1[k:] |
Section 7.4 | |
51620 |
3 in plist |
51621 |
k in play_list |
51213 |
is_a_member = member_id in current_members |
Section 7.5 | |
51212 |
a.reverse() |
51256 |
words.reverse() |
51610 |
play_list.sort() |
51294 |
lst.sort() |
51603 |
plist.append(5) |
51609 |
del alist[k] |
51607 |
del alist[0] |
51608 |
del alist[3] |
51275 |
list3 = [] |
51276 |
list3 = [] for i in range(len(list1)-1, -1, -1): |
51277 |
list3 = [] for i in range(min(len(list1), len(list2))): |
51278 |
list3 = [] for i in range(max(len(list1), len(list2))): |
51284 |
arith_prog = [i for i in range(1, n+1, distance)] |
51285 |
arith_prog = [i for i in range(m, n+1, distance)] |
51287 |
geom_prog = [] i = 1 while i <= n : |
51288 |
fib = [0, 1] i = 1 lastI = 0 while i+lastI <= n : |
51289 |
fib = [] if m <= 0 and n >= 0 : fib.append(0) if m <= 1 and n >= 1 : fib.append(1) i = 1 lastI = 0 while i+lastI <= n : |
51295 |
new_list = [] for i in lst1 : |
51296 |
new_list = [] for i in lst1 : |
Section 7.7 | |
51214 |
duplicates = False k = 0 while k < len(zipcode_list)-1 and not duplicates: |
51215 |
duplicates = False j = 0 while j < len(zipcode_list)-1 and not duplicates: k = j + 1 while k < len(zipcode_list) and not duplicates: if zipcode_list[k] == zipcode_list[j]: duplicates = True k += 1 j += 1 |
51210 |
total = 0.0 for k in temps: |
51216 |
number_of_incompletes = 0 for k in incompletes: |
51219 |
most_tickets = parking_tickets[0] for k in parking_tickets: |
51263 |
sum = 0 for i in numbers : |
51290 |
for e in lst : |
51291 |
if n <= 1 : result = n else : count = 2 i = 1 lastI = 0 while count <= n : lastI, i = i, lastI + i count += 1 result = i |
51292 |
triangulars = [] t = 0 for i in range (1, n+1) : |
51293 |
triangulars = [] t = 0 i = 1 while t+i <= n : |
51297 |
max_dup = -1 for i in range(len(lst)) : |
51150 |
print_list(inventory) |
51163 |
def is_reverse(a, b): |
51283 |
maxPos = 0 for i in range(1, len(names)) : |
51162 |
def sum_list(list): |
Section 7.9 | |
51700 |
t = () |
51701 |
t = (42, 56, 7) |
51702 |
len(t) |
51703 |
t[0] |
51704 |
k = t[0] |
51705 |
t[k] |
51706 |
play_list = list(t) |
51707 |
t = tuple(play_list) |
51708 |
tmp = list(t) tmp.sort() t = tuple(tmp) |
51007 |
repeats = 0 if len(t) != 0 : i=1 while i<len(t) : if t[i] == t[0] : repeats += 1 i += 1 |
MPL Extra | |
51257 |
odds = list(range(1, n+1, 2)) |
51258 |
odds = list(range(m, n+1, 2)) |
51262 |
new_list = [i for i in my_list if i % 2 == 0] |
51264 |
negatives = [i for i in numbers if i < 0] |
51266 |
factors= [i for i in range(2, n) if n % i == 0] |
51267 |
factors= [i for i in range(n-1, 1, -1) if n % i == 0] |