words

Haskell file reading

◇◆丶佛笑我妖孽 提交于 2019-11-28 18:17:49
I have just recently started learning Haskell and I am having a lot of trouble trying to figure out how the file reading works. For example, I have a text file "test.txt" And it contains lines of numbers eg: 32 4 2 30 300 5 I want to read each line and then evaluate each word and add them. Thus I am trying to do something like this so far: import System.IO import Control.Monad main = do let list = [] handle <- openFile "test.txt" ReadMode contents <- hGetContents handle singlewords <- (words contents) list <- f singlewords print list hClose handle f :: [String] -> [Int] f = map read I know

Determine the difficulty of an english word

五迷三道 提交于 2019-11-28 16:49:05
问题 I am working a word based game. My word database contains around 10,000 english words (sorted alphabetically). I am planning to have 5 difficulty levels in the game. Level 1 shows the easiest words and Level 5 shows the most difficult words, relatively speaking. I need to divide the 10,000 long words list into 5 levels, starting from the easiest words to difficult ones. I am looking for a program to do this for me. Can someone tell me if there is an algorithm or a method to quantitatively

Replace four letter word in python

我的未来我决定 提交于 2019-11-28 14:52:37
I am trying to write a program that opens a text document and replaces all four letter words with * *. I have been messing around with this program for multiple hours now. I can not seem to get anywhere. I was hoping someone would be able to help me out with this one. Here is what I have so far. Help is greatly appreciated! def censor(): filename = input("Enter name of file: ") file = open(filename, 'r') file1 = open(filename, 'w') for element in file: words = element.split() if len(words) == 4: file1 = element.replace(words, "xxxx") alist.append(bob) print (file) file.close() here is revised

How to count the letters in a word? [duplicate]

馋奶兔 提交于 2019-11-28 14:21:47
This question already has an answer here: Letter Count on a string 11 answers I am trying to make a Python script which counts the amount of letters in a randomly chosen word for my Hangman game. I already looked around on the web, but most thing I could find was count specific letters in a word. After more looking around I ended up with this, which does not work for some reason. If someone could point out the errors, that'd be greatly appreciated. wordList = ["Tree", "Fish", "Monkey"] wordChosen = random.choice(wordList) wordCounter = wordChosen.lower().count['a', 'b', 'c', 'd', 'e', 'f', 'g'

Converting a sentence string to a string array of words in Java

让人想犯罪 __ 提交于 2019-11-27 17:59:28
I need my Java program to take a string like: "This is a sample sentence." and turn it into a string array like: {"this","is","a","sample","sentence"} No periods, or punctuation (preferably). By the way, the string input is always one sentence. Is there an easy way to do this that I'm not seeing? Or do we really have to search for spaces a lot and create new strings from the areas between the spaces (which are words)? Adam Batkin String.split() will do most of what you want. You may then need to loop over the words to pull out any punctuation. For example: String s = "This is a sample sentence

counting characters and lines from a file python 2.7

不打扰是莪最后的温柔 提交于 2019-11-27 15:55:48
I'm writing a program that counts all lines, words and characters from a file given as input. import string def main(): print "Program determines the number of lines, words and chars in a file." file_name = raw_input("What is the file name to analyze? ") in_file = open(file_name, 'r') data = in_file.read() words = string.split(data) chars = 0 lines = 0 for i in words: chars = chars + len(i) print chars, len(words) main() To some extent, the code is ok. I don't know however how to count 'spaces' in the file. My character counter counts only letters, spaces are excluded. Plus I'm drawing a blank

Replace four letter word in python

偶尔善良 提交于 2019-11-27 09:06:12
问题 I am trying to write a program that opens a text document and replaces all four letter words with * *. I have been messing around with this program for multiple hours now. I can not seem to get anywhere. I was hoping someone would be able to help me out with this one. Here is what I have so far. Help is greatly appreciated! def censor(): filename = input("Enter name of file: ") file = open(filename, 'r') file1 = open(filename, 'w') for element in file: words = element.split() if len(words) ==

290. 单词规律

时间秒杀一切 提交于 2019-11-27 04:47:50
//一直出错,最后才明白字符串的比较不能用==,这是比较的两个地址值,这两个字符串的地址值应该肯定是不一样的,所以需要用equals来比较是否相同,吐血。。。。。 class Solution { public boolean wordPattern(String pattern, String str) { Map<Character,String> map=new HashMap<Character,String>();//存储键值对 Set<String> set=new HashSet<>(); //存储值 String[] words=str.split("\\s+"); //将这个字符串以空格分割 if(pattern.length()!=words.length) return false; for(int i=0;i<pattern.length();i++) { if(!map.containsKey(pattern.charAt(i))) { if(!set.contains(words[i])) { map.put(pattern.charAt(i),words[i]); set.add(words[i]); } else return false; } else { if(!map.get(pattern.charAt(i)).equals(words[i]

Calculating frequency of each word in a sentence in java

人走茶凉 提交于 2019-11-27 01:59:31
I am writing a very basic java program that calculates frequency of each word in a sentence so far i managed to do this much import java.io.*; class Linked { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); System.out.println("Enter the sentence"); String st = br.readLine(); st = st + " "; int a = lengthx(st); String arr[] = new String[a]; int p = 0; int c = 0; for (int j = 0; j < st.length(); j++) { if (st.charAt(j) == ' ') { arr[p++] = st.substring(c,j); c = j + 1; } } } static int lengthx(String a) { int p

PHP: Express Number in Words [duplicate]

我与影子孤独终老i 提交于 2019-11-26 18:44:41
This question already has an answer here: Is there an easy way to convert a number to a word in PHP? 11 answers Is there a function that will express any given number in words? For example: If a number is 1432 , then this function will return "One thousand four hundred and thirty two". Use the NumberFormatter class that are in php ;) $f = new NumberFormatter("en", NumberFormatter::SPELLOUT); echo $f->format(1432); That would output "one thousand four hundred thirty-two" Shahbaz You can do this in many ways I am mentioning here two ways by using The NumberFormatter class as mentioned in