Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 675735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:51:04+00:00 2026-05-14T00:51:04+00:00

Python’s itertools module provides a lots of goodies with respect to processing an iterable/iterator

  • 0

Python’s itertools module provides a lots of goodies with respect to processing an iterable/iterator by use of generators. For example,

permutations(range(3)) --> 012 021 102 120 201 210

combinations('ABCD', 2) --> AB AC AD BC BD CD

[list(g) for k, g in groupby('AAAABBBCCD')] --> AAAA BBB CC D

What are the equivalent in Ruby?

By equivalent, I mean fast and memory efficient (Python’s itertools module is written in C).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:51:05+00:00Added an answer on May 14, 2026 at 12:51 am

    Array#permutation, Array#combination and Enumerable#group_by are defined in ruby since 1.8.7. If you’re using 1.8.6 you can get equivalent methods from facets or active_support or backports.

    Example Usage:

    [0,1,2].permutation.to_a
    #=> [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]]
    
    [0,1,2,3].combination(2).to_a
    #=> [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]]
    
    [0,0,0,1,1,2].group_by {|x| x}.map {|k,v| v}
    #=> [[0, 0, 0], [1, 1], [2]]
    
    [0,1,2,3].group_by {|x| x%2}
    #=> {0=>[0, 2], 1=>[1, 3]}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

python's time module seems a little haphazard. For example, here is a list of
Python has great module for working with iterators called itertools Is there any analog
Python's IDLE has 'Check Module' (Alt-X) to check the syntax which can be called
Python doesn't support complicated anonymous functions. What's a good alternative? For example: class Calculation:
Python decorators are fun to use, but I appear to have hit a wall
Python 2.5 won't let me use this syntax: try: code_that_raises_exception() except Exception as e:
Python's lack of static typing makes it possible to use and rely on classes
Python's subprocess module by default passes all open file descriptors to any child processes
Python 3.2 documentation refers to Collin Winter's functional module which contains function compose :
Python has this wonderful way of handling string substitutions using dictionaries: >>> 'The %(site)s

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.