Page 203 -
P. 203

comprehending data





                                                Tonight’s talk: Does list suffer from set envy?







           List:                                                 Set:
           [sings] “Anything you can do, I can do better. I can
           do anything better than you.”                         I’m resisting the urge to say, “No, you can’t.”
                                                                 Instead, let me ask you: what about handling
                                                                 duplicates? When I see them, I throw them away
                                                                 automatically.
           Can you spell “d-a-t-a  l-o-s-s”? Getting rid of data
           automatically sounds kinda dangerous to me.
                                                                 But that’s what I’m supposed to do. Sets aren’t
                                                                 allowed duplicate values.
           Seriously?
                                                                Yes. That’s why I exist…to store sets of values.
                                                                 Which, when it’s needed, is a real lifesaver.

          And that’s all you do?
                                                                 That’s all I need to do.


          And they pay you for that?!?                          Very funny. You’re just being smug in an effort
                                                                 to hide from the fact that you can’t get rid of

                                                                 duplicates on your own.

           Have you ever considered that I like my duplicate
           values. I’m very fond of them, you know.
                                                                Yeah, right. Except when you don’t need them.
           Which isn’t very often. And, anyway, I can always
           rely on the kindness of others to help me out with
           any duplicates that I don’t need.                     I think you meant to say, “the kindness of set()”,
                                                                 didn’t you?







                                                          To extract the data you need, replace
                                Do this!                  all of that list iteration code in your
                                                          current program with four calls to
                                                          sorted(set(...))[0:3].



                                                                                      you are here 4    167
   198   199   200   201   202   203   204   205   206   207   208