[Solved] Words, sorted by frequency, in a book (.txt file)

[ad_1] if you want to write it in a sorted manner you can do this. from collections import Counter wordlist = open(‘so.py’, ‘r’).read().split() word_counts = Counter(wordlist) write_file = open(‘wordfreq.txt’, ‘w’) for w, c in sorted(word_counts.iteritems(), key=lambda x: x[1], reverse=True): write_file.write(‘{w}, {c}\n’.format(w=w, c=c)) [ad_2] solved Words, sorted by frequency, in a book (.txt file)

[Solved] Bash ping script with LCD error message errors

[ad_1] The following lines of code in your program aren’t C at all. They look like a fragment of shell script: lcd_command(LINE_3); {while true; do ping -c1 192.168.10.30 2>&1 /dev/null; //VPN IP lcd_writechars(“STS300”);} {if [[ ! $? ]]; then lcd_writechars(“VPN Lost”); fi; sleep 10; } This won’t work. Rewrite this code in C. (The system() … Read more

[Solved] How can I set the day of the week as a variable in Swift? [closed]

[ad_1] Assuming you need the name of the current weekday in the current locale: let dateFormatter = NSDateFormatter() dateFormatter.locale = NSLocale.currentLocale() let today = NSDate() let calendar = NSCalendar.currentCalendar() let todayComponents = calendar.components(.CalendarUnitWeekday, fromDate: today) let weekDayIdx = todayComponents.weekday let weekday = dateFormatter.weekdaySymbols[weekDayIdx] as! String println(weekday) // “Wednesday” [ad_2] solved How can I set the … Read more

[Solved] How to backup my mongoDB documents?

[ad_1] MongoDump. I used it to export my database to a separate server and it can also be used to take backups, otherwise to safely store data on remote servers look up sharding or replication. Further reading: backup strategies. 0 [ad_2] solved How to backup my mongoDB documents?

[Solved] C# editing string

[ad_1] Step one: use var arr = string.Split(new string[] {“.”}, StringSplitOptions.None) to get an array of strings. arr[2] should contain your number. Step two: use Convert.ToInt32() to convert this string to an int. Step 3: increase / decrease this int by two Step 4: Write the number back to the were it was saved in … Read more

[Solved] Delegates vs Calling of Functions [closed]

[ad_1] Well, “the essential idea” of “delegation” is simply: “identify Someone Else that you can ask.” In this example, the Compare class exists to “compare two objects.” But you’ve said that it is to delegate that responsibility to some other function that is not a part of its own definition. Furthermore, you specify exactly what … Read more

[Solved] Getting started with basic transportation problems like Wolf, Cabbage, Goat with either C# or F# [closed]

[ad_1] I’d recommend going thru the excellent article Escape from Zurg: An Exercise in Logic Programming. Although the functional language of choice there is Haskell, it should give you enough ideas about programming of optimal search problems functionally. Also Escape from Zurg in Scala has full source code easily portable to F#. [ad_2] solved Getting … Read more

[Solved] What would the ruby equivalent be to this python script?

[ad_1] Python: print (“{0:5s} {1:7s} {2:9s} {3:6s} {4:25s} {5:s}”.format(‘Rank’, ‘Points’, ‘Comments’, ‘Hours’, ‘Sub’, ‘Link’)) Ruby: puts “%-5s %-7s %-9s %-6s %-25s %-5s” % [‘Rank’, ‘Points’, ‘Comments’, ‘Hours’, ‘Sub’, ‘Link’] Alternatively: puts sprintf(“%-5s %-7s %-9s %-6s %-25s %-5s”, *[‘Rank’, ‘Points’, ‘Comments’, ‘Hours’, ‘Sub’, ‘Link’]) 1 [ad_2] solved What would the ruby equivalent be to this python … Read more

[Solved] How to get control values and modify them in Page Methods?

[ad_1] Quick example: <asp:ScriptManager runat=”server” EnablePageMethods=”true” /> <!– or ToolkitScriptManager, but remember to put only one –> <script type=”text/javascript”> function invokeMethod() { x = document.getElementById(‘<%= TextBox1.ClientID %>’).value; PageMethods.theMethod(x, OnSuccess, OnFailure); } function OnSuccess(r) { document.getElementById(‘<%= TextBox1.ClientID %>’).value = r; } function OnFailure(r) { alert(r._message); } </script> [System.Web.Services.WebMethod()] public static string theMethod(string x) { return x … Read more

[Solved] nullpointer exception in parsing string to date [closed]

[ad_1] First make sure that from2 is not null and data getting from db is not null. Following added the success and failure cases, String from2 = “01-12-2015”; SimpleDateFormat simpleDateFromat = new SimpleDateFormat(“dd-MM-yyyy”); Date dateFROM = simpleDateFromat.parse(from2); System.out.println(“dateFROM : “+dateFROM); Here you will get the correct date as : Tue Dec 01 00:00:00 IST 2015 … Read more