Re: [Tutor] Tutor Digest, Vol 166, Issue 21
>> However, I am stuck. I have below code which is not working. I don't know how to achieve this programmatically: sorted by the number of occurrences in a descending order. If two or more words have the same count, they should be sorted alphabetically (in an ascending order). > > Define "not working" > Do you get an error message? (show us) I am not getting any error message but i don't know how to get the expected result. #getting: [('just', 4), ('practice', 3), ('perfect', 2), ('youll', 1), ('makes', 1), ('get', 1), ('by', 1)] #expected: [["just","4"],["practice","3"],["perfect","2"],["makes","1"],["youll","1"],["get","1"],["by","1"]] > If the output different to what you expect (show us) explained above. > > Have you tried printing the intermediate results? I did but I don't know how to get what i am looking for. > For example the dictionary before you sort it? > Or what about using the default sort, how close is that? > > Don't expect us to run your code and check the output. https://paste.pound-python.org/show/NappXV9daDMFz64yA805/ With the above code, i don't know what we can modify this to get expected result as below: #getting: [('just', 4), ('practice', 3), ('perfect', 2), ('youll', 1), ('makes', 1), ('get', 1), ('by', 1)] #expected: [["just","4"],["practice","3"],["perfect","2"],["makes","1"],["youll","1"],["get","1"],["by","1"]] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] installation of Python 2.7 an 3.6, feedback
On 24/12/17 15:36, marcus lütolf wrote: while working through Alan C. Gould‘s excellent update on‘ Learning to Program‘ I copied OK, First I need to point out that the tutorial content has not changed, it is still the old c2010-12 material. The update is to the structure and cosmetics to make it more mobile friendly. I'm hoping to launch the new site in January and then start a topic by topic update to v3.7 spec. import sys inp = sys.stdin.readline() while inp.strip != '': notice that should be strip()... with parens. print(inp) inp = sys.stdin.readline() in my IDLE 3.6 location and another copied a second file in one of my personal folders in my PC (W 10). If I open echoinput.py in IDLE 3.6 I get the script as written. If I open and edit it in my personal folder it opens in a Python 2.7 window although, I deleted Python 2.7 previously. Presumably you have a second copy. some PC vendors use Python in their admin tools so it may have been installed when you got the PC. Maybe. Further on, if I add a print statement to echoinput.py it gets printed regardless of parenteses or none in the echoinput.py file in my personal folder. Certainly sounds like you are running v2.X Finally a may be too late comment on the update of ‘Learning to Program : Personally I would appreciate a definition of an instance Hmm, I thought I did, maybe in the Raw Materials topic, or maybe in the OOP topic. On the other hand instance is a standard English word used in its normal meaning (ie not with a Computer specific meaning) so maybe I didn't. Hmm, there is a very terse explanation in the OOP topic but I think I was relying on the English definition being sufficient. and in referring to Windows XP Home in the ‚Coding Style‘ section (Note for Windows users) I thought W XP has expired. Indeed it has, at least so far as official support goes. There are still plenty of folks using it. But that is the kind of stuff that will be updated next year- hopefully along with the screen shots etc. Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Installing python and numpy on the Mac (OSX)
See Anaconda, a py dist packed with sci modules. Comes bundled with lots of goodies ! Abdur-Rahmaan Janhangeer, Mauritius abdurrahmaanjanhangeer.wordpress.com On 23 Dec 2017 12:45, "Peter Hodges"wrote: > Hi. I downloaded Python 3.6 from the python site, then followed online > directions for pip to install numpy (in users? —user was in the example). > When I start IDLE in the Python 3.6 in Applications and then type import > numpy as np I get the following: > import numpy as np > Traceback (most recent call last): > File " ", line 1, in > import numpy as np > ModuleNotFoundError: No module named ‘numpy' > > Does this mean I need to set the $PATH with some new pathname? > Or move the numpy directory into the python 3.6 directory? > Or? > > Thanks for any help, > Peter > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] installation of Python 2.7 an 3.6, feedback
dear experts, while working through Alan C. Goulds excellent update on Learning to Program I copied the file echoinput.py from the Conversing with the user section: import sys inp = sys.stdin.readline() while inp.strip != '': print(inp) inp = sys.stdin.readline() in my IDLE 3.6 location and another copied a second file in one of my personal folders in my PC (W 10). If I open echoinput.py in IDLE 3.6 I get the script as written. If I open and edit it in my personal folder it opens in a Python 2.7 window although, I deleted Python 2.7 previously. Further on, if I add a print statement to echoinput.py it gets printed regardless of parenteses or none in the echoinput.py file in my personal folder. What causes this odd behavior ? Finally a may be too late comment on the update of Learning to Program : Personally I would appreciate a definition of an instance and in referring to Windows XP Home in the Coding Style section (Note for Windows users) I thought W XP has expired. Marcus Luetolf --- Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft. https://www.avast.com/antivirus ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sort by value and then by key
On 24/12/17 08:12, anish singh wrote: > However, I am stuck. I have below code which is not working. Define "not working" Do you get an error message? (show us) If the output different to what you expect (show us) Have you tried printing the intermediate results? For example the dictionary before you sort it? Or what about using the default sort, how close is that? Don't expect us to run your code and check the output. You've already done that so share the information. > > > import collections > > x = collections.OrderedDict() > import collections > import operator > > > def make_comparator(x, y): > if x[1] > y[1]: > return 1 > elif x[1] < y[1]: > return -1 > elif x[1] == y[1]: > if x > y: > return 1 > elif x < y: > return -1 > return 0 > > > document = "Practice makes perfect. you'll only get Perfect by > practice. just practice!" > words = document.split() > d = collections.defaultdict(int) > for word in words: > word = word.lower() > word = [c if c >= 'a' and c <= 'z' else "" for c in word] > word = "".join(word) > d[word] += 1 > output = [] > for key, value in sorted(d, cmp = make_comparator(x)): > output.append([key, value]) > print(output) > - -- 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
[Tutor] vol 166, issue 20, 1. installing python and numpy on the Mac (OSX) (Peter Hodges)
sudo -H python3.6 -m pip install numpy ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] sort by value and then by key
document = "Practice makes perfect. you'll only get Perfect by practice. just practice!" output: [ ["practice", "3"], ["perfect", "2"], ["by", "1"], ["get", "1"], ["just", "1"], ["makes", "1"], ["only", "1"], ["youll", "1"] ] I am supposed to return a list of all unique words in it and their number of occurrences, sorted by the number of occurrences in a descending order. If two or more words have the same count, they should be sorted alphabetically (in an ascending order). However, I am stuck. I have below code which is not working. import collections x = collections.OrderedDict() import collections import operator def make_comparator(x, y): if x[1] > y[1]: return 1 elif x[1] < y[1]: return -1 elif x[1] == y[1]: if x > y: return 1 elif x < y: return -1 return 0 document = "Practice makes perfect. you'll only get Perfect by practice. just practice!" words = document.split() d = collections.defaultdict(int) for word in words: word = word.lower() word = [c if c >= 'a' and c <= 'z' else "" for c in word] word = "".join(word) d[word] += 1 output = [] for key, value in sorted(d, cmp = make_comparator(x)): output.append([key, value]) print(output) Thanks, ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor