[Solved] Find All Possible Fixed Size String Python

You can use itertools.product for this. It returns a generator of sequences of fixed length. As you order your strings first by length and then lexicographically, you may use something like this import itertools for l in range(1, 5): for seq in itertools.product(“abc”, repeat=l): print(“”.join(seq)) 3 solved Find All Possible Fixed Size String Python

[Solved] applying onehotencoder on numpy array

Don’t use a new OneHotEncoder on test_data, use the first one, and only use transform() on it. Do this: test_data = onehotencoder_1.transform(test_data).toarray() Never use fit() (or fit_transform()) on testing data. The different number of columns are entirely possible because it may happen that test data dont contain some categories which are present in train data. … Read more

[Solved] Using the List Feature in Python

def days_in_month(month): for m, nblist in month_days: if month==m: return nblist else: return [] days_in_month(‘May’) Out[20]: [31] days_in_month(‘Mady’) Out[21]: [] solved Using the List Feature in Python

[Solved] Summing the digits of a very large number [closed]

This would be a complete implementation in Haskell import Data.List.Split (chunksOf) import Data.List import Data.Char (digitToInt) main :: IO () main = do digits <- map digitToInt <$> readFile “pifile.txt” let summator = foldl1′ (zipWith (+)) . chunksOf 4 print $ summator digits I will update this with some explanation later this day. Update @Comments … Read more

[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] 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] function with arguments in python [closed]

def count(word, letter): count = 0 for l in word: if l == letter: count = count + 1 return count word = raw_input(‘Enter a string:’) letter = raw_input(‘Enter a character:’) print count(word, letter) solved function with arguments in python [closed]

[Solved] Using Bottle, need to create web-page [closed]

This is less of a Python question and more of an HTML question. You’ll still need to write most of the page in HTML and then only ‘deliver’ the page to the user using Python, with Bottlepy, as you’ve mentioned . You’ll need to learn about HTML Forms and Inputs to get anything done effectively. … Read more

[Solved] Web Scraping particular tags using Python [closed]

There is an incredible scraping library for Python called BeautifulSoup which will make your life much easier: http://www.crummy.com/software/BeautifulSoup/ BeautifulSoup allows you to select by html tags and/or html attributes such via a css class name. It also handles bad html docs really well but you need to read the docs on how it works. It’s … Read more

[Solved] Any idea why hackerrank doesn’t accept my code even if it prints exactly what is asked

You have an extra line of spaces on the top Try this- import math import os import random import re import sys # Complete the staircase function below. def staircase(n): for x in range(1,n+1): print((n-x)*” “+”#”*x) if __name__ == ‘__main__’: n = int(input()) staircase(n) solved Any idea why hackerrank doesn’t accept my code even if … Read more