Monday 30 September 2013

PYTHON WEEK 7 SOLUTIONS

                               WEEK 7 SOLUTIONS



1.                                     d['c'] = 3           (in case of {'a': 1, 'c': 3, 'b': 2}  )



2.                                     d['b'] = 3           (in case of {'a': 1, 'b': 3}  )


3.                                     d['a'].append(2)        ,         d['a'].insert(1, 2)
                                       d['a'].sort()



4.                                     "b" in d    ,     'b' in d     ,    not ('e' in d)

5.                                     len(d['b'])    ,     len(d)     ,   len(d['a']) + len(d['c'])

6.                                     tup[-2] = 4   ,   tup.reverse()   ,   tup.append(4)

7.                                     ('single',)     ,     (1, 'fred', 2.0)

8.

L = []
for k in d:
    L.extend(d[k])

total = len(L)



total = 0
for k in d:
    total = total + len(d[k])




9.                                      {1: 30}

10.                            

Populates dictionary d where each key is the first item of each inner list of L and each value is the second item of that inner list.


11.                                     

Try to eat one of each fruit: reduce by 1 all quantities greater than 0
associated with each fruit in d and return True if and only if any fruit was
eaten.


12.        

for k in d:
        for i in range(len(d[k])):
            if d[k][i] == v:
                found = True



for k in d:
        if v in d[k]:
            found = True

Thanx To Saurav Gupta

No comments:

Post a Comment