anagram

Code golf: find all anagrams

旧巷老猫 提交于 2019-12-02 22:54:51
A word is an anagram if the letters in that word can be re-arranged to form a different word. Task: The shortest source code by character count to find all sets of anagrams given a word list. Spaces and new lines should be counted as characters Use the code ruler ---------10--------20--------30--------40--------50--------60--------70--------80--------90--------100-------110-------120 Input: a list of words from stdin with each word separated by a new line. e.g. A A's AOL AOL's Aachen Aachen's Aaliyah Aaliyah's Aaron Aaron's Abbas Abbasid Abbasid's Output: All sets of anagrams, with each set

Anagrams finder in javascript

我怕爱的太早我们不能终老 提交于 2019-12-02 22:00:58
I am supposed to write a program in JavaScript to find all the anagrams within a series of words provided. e.g.: "monk, konm, nkom, bbc, cbb, dell, ledl, llde" The output should be categorised into rows: 1. monk konm, nkom; 2. bbc cbb; 3. dell ledl, llde; I already sorted them into alphabetical order i.e.: "kmno kmno bbc bbc dell dell" and put them into an array. However I am stuck in comparing and finding the matching anagram within the array. Any help will be greatly appreciated. Javascript objects are excellent for this purpose, since they are essentially key/value stores: // Words to match

== comparisons against lines from readlines() fail

血红的双手。 提交于 2019-12-02 10:12:29
I am currently working on a small anagram program that takes all possible permutations of a word and compare them with a dictionary. However, I am unable to get the results to print. The culprit appears to be the == operator, if I put ''.join(words[i]) == compare[j] nothing prints, however, if I input hi and run the program with ''.join(words[i]) == "hi" the entire dictionary prints, but if I invert it to "hi" == compare[j] nothing prints. Thanks in advance for any help! import itertools run = input("Please enter a word: ") dictionary = "dictionary.txt" #input("Please enter the name of the

Anagram Python 3 [closed]

十年热恋 提交于 2019-12-02 02:41:36
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I'm trying to write a program that checks whether 2 inputs are anagrams. I feel like this should be relatively easy but I can't seem to figure it out. I'm supposed to define a function as: def isAnagram(s1, s2): so far, I have this: word1 = input("Enter a string: ") word2 = input("Enter a second string: ") def

Anagram Python 3 [closed]

强颜欢笑 提交于 2019-12-01 23:54:27
I'm trying to write a program that checks whether 2 inputs are anagrams. I feel like this should be relatively easy but I can't seem to figure it out. I'm supposed to define a function as: def isAnagram(s1, s2): so far, I have this: word1 = input("Enter a string: ") word2 = input("Enter a second string: ") def isAnagram(s1, s2): s1 = word1.sort() s2 = word2.sort() if s1 == s2: print("This is an anagram") else: print("This is not an anagram) isAnagram() I guess I don't fully understand defining functions, so if you could please explain what's happening, that would be great! You've defined the

Finding and grouping anagrams by Python

六眼飞鱼酱① 提交于 2019-12-01 20:28:21
input: ['abc', 'cab', 'cafe', 'face', 'goo'] output: [['abc', 'cab'], ['cafe', 'face'], ['goo']] The problem is simple: it groups by anagrams . The order doesn't matter. Of course, I can do this by C++ (that's my mother tongue). But, I'm wondering this can be done in a single line by Python . EDITED: If it's not possible, maybe 2 or 3 lines. I'm a newbie in Python. To check whether two strings are anagram, I used sorting. >>> input = ['abc', 'cab', 'cafe', 'face', 'goo'] >>> input2 = [''.join(sorted(x)) for x in input] >>> input2 ['abc', 'abc', 'acef', 'acef', 'goo'] I think it may be doable

How to write an anagram generator in pure C# and .Net framework [closed]

老子叫甜甜 提交于 2019-12-01 18:11:18
I would like to generate anagram output of a given string without the help of any external libraries such as Google anagram algorithms helper. Example: Input string = "GOD" Output list should look like the following one: G O D GO GD OD OG DG DO GOD GDO ODG OGD DGO DOG That taks turned to be awesome on so many levels. I present you a pure LINQ (but not very efficient) solution. static class Program { static void Main(string[] args) { var res = "cat".Anagrams(); foreach (var anagram in res) Console.WriteLine(anagram.MergeToStr()); } static IEnumerable<IEnumerable<T>> Anagrams<T>(this IEnumerable

How to write an anagram generator in pure C# and .Net framework [closed]

旧街凉风 提交于 2019-12-01 17:29:13
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I would like to generate anagram output of a given string without the help of any external libraries such as Google anagram algorithms helper. Example: Input string = "GOD" Output list should look like the

How can I simplify or clean up this anagram method?

懵懂的女人 提交于 2019-12-01 01:59:30
I have a method here that takes an array of strings and groups the ones that are anagrams of each other together, with each group forming a sub-array of the main anagram_groups array. The output is fine but I feel like my code is probably overly-complicated. How could my logic and/or syntax be simplified, short of refactoring things into more methods? def combine_anagrams(words) anagram_groups = [] # For each word in array argument words.each do |word| # Tracking variable for the word word_added = false anagram_groups.each do |group| # Check if word already exists (prevents duplicates) if

Rearrange Letters from Array and check if arrangement is in array

家住魔仙堡 提交于 2019-11-30 16:12:08
I'm Making a an ios application where you input 9 lettes and it will output anagrams of those 9 letters. It is like the target word, or 9 letter word in the paper. Like this link: http://nineletterword.tompaton.com/ It doesn't just provide anagrams for 9 letters, it will do it for 4 letters, 5 letters, 6 letters... all of which contain at least the middle letter. I want to make it an offline application, so I don't want to reference any websites or use an online json... How would I go about checking if an array of the 9 letters can be rearranged into a word which is in an English dictionary