How to group anagrams in a string into an array
来源:互联网 发布:淘宝自动确认订单信息 编辑:程序博客网 时间:2024/04/30 09:24
I want to group anagrams in ruby from a given string and the result should be an array containing arrays of anagram groups like
Given String: "scream cars for four scar creams"
here cars and scar are anagrams(made by same characters)
Given String: "scream cars for four scar creams"
here cars and scar are anagrams(made by same characters)
and the result should be [[cars, scar], ['for'], ['four'], ['creams', 'scream']]
"scream cars for four scar creams".split.group_by{|w| w.chars.sort}.values#=> [["scream", "creams"], ["cars", "scar"], ["for"], ["four"]]
0 0
- How to group anagrams in a string into an array
- How to split a string to array in objective-c?
- How to copy values of an array into another array
- How to remove the duplicated value in a String array
- How to sort an array of hashes into hashes with multiple values for a key?
- How to define an array in c#.
- How to initialize an array in C
- how to remove nil and blank string in an array in Ruby
- How to sort an array in Ruby to a particular order?
- How to find number of a specific integer in an array of Fixnums ruby
- How to Check if an Array Contains a Value in Java Efficiently?
- How to import an oracle dump into a different tablespace
- How to compile a TCL script into an EXE program
- How to burn an ISO-image into a DVD
- How to format strings in an array in ruby?
- How to: Load Unmanaged Resources into a Byte Array
- Matching Portions of A String to Elements of an Array in Ruby
- How Do I Convert an Integer to a String in Excel VBA
- Android自定义ScrollView分段加载大文本数据到TextView
- 排序算法总结
- 未关闭防火墙导致tomcat启动后访问无响应
- 关于onCreate方法的参数 Bundle savedInstanceState的作用
- 很全面的二叉树相关操作
- How to group anagrams in a string into an array
- strcpy和memcpy的区别
- UVA 1486 - Transportation(网络流+拆边)
- 面向对象设计的六大原则简介
- JavaScript中简洁实用的HashMap对象
- 关于Uml导图
- android开源项目---RoundedImageView制作圆角矩形,椭圆形以其圆形控件
- X509证书结构和ASN.1编码
- Android DecorView浅析