[Tutor] Lost in the control flow
Adam Bark
adam.jtm30 at gmail.com
Fri Aug 13 22:38:20 CEST 2010
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100813/a766fce2/attachment.html>
More information about the Tutor
mailing list