[Tutor] Lost in the control flow

Eduardo Vieira eduardo.susan at gmail.com
Mon Aug 16 23:49:06 CEST 2010


On Fri, Aug 13, 2010 at 2:38 PM, Adam Bark <adam.jtm30 at gmail.com> wrote:
> On 11/08/10 18:14, Eduardo Vieira wrote:
>
> On Tue, Aug 10, 2010 at 1:56 PM, Adam Bark <adam.jtm30 at gmail.com> wrote:
>
>
>
> The problem is you don't call make_dict unless there's a "FUEL SURCHARGE" or
> multiple pins. Also you don't add the first pin to mydict["tracking"] unless
> there's a "FUEL SURCHARGE".
>
> HTH,
> Adam.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
> Hi, I made these changes, got rid of the functions, and changed some logic:
> here is the link: http://pastebin.com/F19vKUjr
>
> Now mydict will be changing, of course with every loop, as the output below:
> {'company': 'CITY SIGNS', 'tracking': ['600775301143'], 'id': '1'}
> {'city': 'MEDICINE HAT', 'company': 'CITY SIGNS', 'tracking':
> ['600775301143'], 'id': '1', 'prov': 'AB'}
> {'city': 'MEDICINE HAT', 'company': 'TRIMLINE', 'tracking':
> ['600775301150'], 'id': '2', 'prov': 'AB'}
> {'city': 'ROCKY MOUNTAIN HOUSE', 'company': 'TRIMLINE', 'tracking':
> ['600775301150'], 'id': '2', 'prov': 'AB'}
> {'city': 'ROCKY MOUNTAIN HOUSE', 'company': 'TS SIGNS PRINTING &
> PROMO', 'tracking': ['600775301168'], 'id': '3', 'prov': 'AB'}
> {'city': 'FORT MCMURRAY', 'company': 'TS SIGNS PRINTING & PROMO',
> 'tracking': ['600775301168'], 'id': '3', 'prov': 'AB'}
> {'city': 'FORT MCMURRAY', 'company': 'TS SIGNS PRINTING & PROMO',
> 'tracking': ['600775301168', '600775301168'], 'id': '3', 'prov': 'AB'}
> {'city': 'FORT MCMURRAY', 'company': 'TS SIGNS PRINTING & PROMO',
> 'tracking': ['600775301168', '600775301168', '600775301176'], 'id':
> '3', 'prov': 'AB'}
> {'city': 'FORT MCMURRAY', 'company': 'TS SIGNS PRINTING & PROMO',
> 'tracking': ['600775301168', '600775301168', '600775301176',
> '600775301184'], 'id': '3', 'prov': 'AB'}
> {'city': 'FORT MCMURRAY', 'company': 'TS SIGNS PRINTING & PROMO',
> 'tracking': ['600775301168', '600775301168', '600775301176',
> '600775301184', '600775301192'], 'id': '3', 'prov': 'AB'}
> {'city': 'FORT MCMURRAY', 'company': 'TS SIGNS PRINTING & PROMO',
> 'tracking': ['600775301168', '600775301168', '600775301176',
> '600775301184', '600775301192', '600775301200'], 'id': '3', 'prov':
> 'AB'}
> so I appended everything to a bigdata list and used it to update the
> dictionary data_dict
>
> I can't understand why I get only one value:
> {'18': {'city': 'ESTEVAN',
>         'company': 'BRAKE & DRIVE SYSTEMS',
>         'id': '18',
>         'prov': 'SK',
>         'tracking': ['600775301515', '600775301515', '600775301523']}}
>
> Regards,
>
> Eduardo
>
>
> It looks to me like you keep overwriting the previous data, you keep using
> mydict. Doing an append does not copy the dictionary it just copies a
> reference to the underlying data structure.
>

Thank you, Adam. That was the problem. By using deepcopy I managed to fix it:
 final = deepcopy(mydict)

Cheers,

Eduardo


More information about the Tutor mailing list