Re: [Tutor] python memory management
Thank you all for your explanations. I really enjoy learning about things like that. Monika -- Original Message -- From: Alan Gauld via Tutor To: zakaria , tutor@python.org Subject: Re: [Tutor] python memory management Date: Sun, 4 Sep 2016 01:22:27 +0100 On 03/09/16 23:20, zakaria wrote: > Is there any practical usage of using reference cycling? There are a (very) few cases where data structures require the creation of cyclic references. One example I've used is in managing comms networks where nodes are multiply and/or cyclically linked and you need to build those linkages into your data model. In those cases you need to manage the cleanup yourself. But most cyclic references occur by accident, the programmer probably didn't intend them to exist but it just so happened that one object points to another which happens to point at another which in turn points at the first. The cycle can span many objects. Think of a directory tree where a deeply nested node has a link pointing back at a root level node. But the root also indirectly points at that low level node by means of the tree structure... As a specific example, It often happens in GUIs where widgets hold references to other widgets higher in the widget parent/child tree. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor Unlock Visions (Sponsored by Content.Ad) 1 Odd Method 'Restores' Your 20/20 Vision. Try This http://thirdpartyoffers.netzero.net/TGL3241/57cb93756ab9c13757ae2st02duc ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 'int' object has no attribute 'items'
Chidinma via Tutor wrote: > Hello,Am trying to solve a problem, but keep getting different errors. > Country X calculates tax for its citizens using a graduated scale rate as > shown below: >- Yearly Income: 0 - 1000Tax Rate: 0% >- Yearly Income: 1,001 - 10,000Tax Rate: 10% >- Yearly Income: 10,001 - 20,200Tax Rate: 15% >- Yearly Income: 20,201 - 30,750Tax Rate: 20% >- Yearly Income: 30,751 - 50,000Tax Rate: 25% >- Yearly Income: Over 50,000Tax Rate: 30% > Am trying to write a Python function that will calculate tax rate. Perhaps you misunderstood the task and you were asked to write a simpler function that takes a value and calculates the tax. For example, in a country with a rate of 50% for everyone the solution would look like this... # expected? def caculate_tax(income): return 0.5 * income ...but you wrote something similar to def calculate_tax(payer_income_pairs): return { payer: income * 0.5 for payer, income in payer_income_pairs.items()} > def calculate_tax(dict_inp): result = {} if dict_inp == {}:result = > "Please enter valid inputs" else:for k, v in dict_inp.items(): > try:x = int(dict_inp[k]) except ValueError: > print("That's not an int!")break if(x):if x > 5: Awful. Please change your configuration to preserve newlines before posting more code. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor