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

  • Home
  • SEARCH
  • 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 5991351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:22:27+00:00 2026-05-22T23:22:27+00:00

I just learned yesterday from this site that I can: class Seq(object): def __init__(self,

  • 0

I just learned yesterday from this site that I can:

class Seq(object):
    def __init__(self, seq):
        self.seq = seq
    def __repr__(self):
        return repr(self.seq)
    def __str__(self):
        return str(self.seq)
    def all(self):
        return Seq(self.seq[:])
    def head(self, count):
        return Seq(self.seq[:count])
    def tail(self, count):
        return Seq(self.seq[-count:])
    def odd(self):
        return Seq(self.seq[1::2])
    def even(self):
        return Seq(self.seq[::2])
    def reverse(self):
        return Seq(self.seq[::-1])

>>> s = Seq(range(0, 100))
>>> print s.head(10).odd().even().reverse()
[9, 5, 1]

I want to enumerate possible combination of those sequence method chains inside of class Seq, may sort of:

itertools.product([s.head,s.odd,s.even,s.reverse], repeat=4)    
# may not just limited those 4 functions
  1. how to use the itertools.product() to

    1). generate invoke-able function chains list? just like this:

    foo = s.head().odd().even().reverse()

    2). generate eval()able chain strings then I can store in ascii file or eval() later or for logging purpose?

  2. the head(), tail() may accept parameter, and even(), odd() is not need to, for example,
    the paremeter of head() and tail() may from lists:

      head_lmt = [10,20,30]
      tail_lmt = [30,40,50]
      foo = s.head().odd().tail().reverse()
                   ^------------------------------------head_lmt  10 or 20 or 30
                                ^-----------------------tail_lmt  30 or 40 or 50
    

If my Q1 is possible, how I can fill those parameter into the invoke-able list and the eval()-able string, a.k.a generate more specific invoke-able list and the eval()-able string?

Thanks!

  • 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-22T23:22:28+00:00Added an answer on May 22, 2026 at 11:22 pm

    Note that something like “s.head()” means a method which is “bound” to that specific instance of Seq, that is, “s.” Something like “Seq.head()” means a method which is unbound, so one can still pass in different instances of Seq.

    From there it simply requires basic functional composition and string concatenation.

    def chain_method(from_method, to_method):
        def inner(arg):
            return to_method(from_method(arg))
        return inner
    
    possible_funcs = []
    log_strings = []
    for possible_combo in itertools.product([Seq.head,Seq.odd,Seq.even,Seq.reverse], repeat=4):
        meta_method = possible_combo[0]
        for method in possible_combo[1:]:
            meta_method = chain_method(meta_method, method)
        log_string = []
        for method in possible_combo:
            log_string.extend(['.', method.__name__, '()'])
        possible_funcs.append(meta_method)
        log_strings.append("".join(log_string))
    

    I’m not sure what you mean by the examples for the additional parameters, though. How do you intend to combine the different parameter values with the different combinations of functions?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just learned about ngrep , a cool program that lets you easily sniff
I just learned something interesting. The add method for the javascript select object in
I have always written regexes like this <A HREF=([^]*) TARGET=_blank>([^<]*)</A> but I just learned
I've got an application that just shipped. Since I wrote it, I've learned about
This is really an extension of my question yesterday where I learned about apply.weekly
I just learned about java.sql package . It uses Class.forName() to dynamically load the
I just learned that $ requires an escape character. What other special characters are
I just learned that there are two types(?) of mySQL functions--mysql and mysqli. On
Today I just learned that Adobe Air has a local SQL database, which is
I come from a .NET background and just learned Ruby On Rails. My company

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.