Re: ps9. In order to avoid specifying shapes in ShapeSet(), I used sorted() to arrange the strings by type. It works ok but the results for Circle are neither in the order presented in the handout nor 'numerical' as such. Out of curiousity, what is being sorted? Here is the code and results: http://pastebin.com/qEBHw0tA Thanks
get the shape strings in a list, sort the list, return the list as a string concatenated with linefeeds http://dpaste.com/754168/
Ok, so turns out i was originally sorting a list based on the location of the objects (ie <__main__.Circle object at 0x00B642B0>) not the string representation (ie Circle with radius 2.0). I made a new list with strings and sorted that (as was suggested above). However, the handout example is sorted by the type of object or first word of the string only...so I had to split and sort a slightly different way. Hope it makes sense...?! Here it is: http://pastebin.com/UrBa769z Should I try tackling readShapesFromFile() without using specific shapes or do you think it might be too complicated at the moment?
using the key and cmp arguments with sorted is realy cool/powerful. i made my shapeset a dictionary with the shape's string as the key and the shape object as the value - that made it easy for the parameters of this pset. http://dpaste.com/754569/ I don't understand what you mean by "..without using specific shapes.." If your code only knows about certain kinds of shapes (you have only defined certain types of shapes), readShapesFromFile needs to account for that - I opted to not add an undefined shape to the ShapeSet
Your sorted list returned 'Circle...19.4' as the first object for me. I was trying to order only by category, first in, first out...By the way, any reason why you chose string over the object for the key? What I meant by 'without specific shapes' : I was thinking that the shape from the file (line[0]) and its measurements (line[2]:) might be added to a ShapeSet without having triangle, circle, square, in the code. Something like: x = 'Triangle' y = x +'(2,3)' Set = ShapeSet() Set.addShape(y) That way if ,say, an oval is added to the file, only a class Oval() would need to be created...I know it's a bit much for this exercise, but just wondering... Anyway, thanks for your help. It was appreciated.
it probably had something to do with the dictionary keys being unique so it kinda reinforced the idea of having only one of a shape in the set. that way you don't have to check for duplicates, it is automatic.
Join our real-time social learning platform and learn together with your friends!