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

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)) solved Words, sorted by frequency, in a book (.txt file)

[Solved] Bash ping script with LCD error message errors

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() function … Read more

[Solved] fastest way to compare string elements with each other

The amount of downvotes is crazy but oh well… I found the reason for my performance issue / bottleneck thanks to the comments. The second for loop inside StartSimilarityCheck() iterates over all entries, which in itself is no problem but when viewed under performance issues and efficient, is bad. The solution is to only check … Read more

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

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” solved How can I set the day of … Read more

[Solved] How to backup my mongoDB documents?

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 solved How to backup my mongoDB documents?

[Solved] C# editing string

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 the … Read more

[Solved] Delegates vs Calling of Functions [closed]

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 an … Read more

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

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#. solved Getting started with … Read more

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

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 solved What would the ruby equivalent be to this python script?

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

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]

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 from2 … Read more