--1926193751-250232837-1186836270923 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-250232837-1186836270=:3923" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-250232837-1186836270923 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Sat, 11 Aug 2007, Peñá, Botp wrote: > From: Andrew Savige [mailto:ajsavige / yahoo.com.au] > # s = "ZBBBCZZ" > # x = s.scan(/((.)\2*)/).map {|i| i[0]} > > when it comes to string patterns like this, nothing beats regex > > # import itertools > # s = "ZBBBCCZZ" > # x = [''.join(g) for k, g in itertools.groupby(s)] > # Does anyone know if Ruby has a similar library to Python's itertools? > > hmm, you seem to like this than your previous regex+map solution, why? (isk because i prefer your first solution --not that it's ruby) > > in 1.9 or the upcoming ruby, it keeps getting better and better and may look like this, > > s = "ZBBBCZZ" > x = s.split('').group_by{|x| x}.entries > > or possibly to > > x = s.split('').group_by.entries I'm going to have to get special glasses that can read invisible ink.... :-) David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) --1926193751-250232837-1186836270923-- --1926193751-250232837-1186836270923--