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 6879719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:52:55+00:00 2026-05-27T04:52:55+00:00

I am stuck trying to perform this task and while trying I can’t help

  • 0

I am stuck trying to perform this task and while trying I can’t help thinking there will be a nicer way to code it than the way I have been trying.

I have a line of text and a keyword. I want to make a new list going down each character in each list. The keyword will just repeat itself until the end of the list. If there are any non-alpha characters the keyword letter will not be used.

For example:

Keyword="lemon"
Text="hi there!"

would result in

('lh', 'ei', ' ', 'mt' , 'oh', 'ne', 'lr', 'ee', '!')

Is there a way of telling python to keep repeating over a string in a loop, ie keep repeating over the letters of lemon?

I am new to coding so sorry if this isn’t explained well or seems strange!

  • 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-27T04:52:56+00:00Added an answer on May 27, 2026 at 4:52 am

    Here’s a solution:

    import itertools
    
    def task(kw,text):
        i = itertools.cycle(kw)
        return tuple(next(i)+t if t.isalpha() else t for t in text)
    
    print(task('lemon','hi there!'))
    

    Output

    ('lh', 'ei', ' ', 'mt', 'oh', 'ne', 'lr', 'ee', '!')
    

    itertools.cycle iterates over a sequence repeatedly (a string is a sequence of characters). next gets the next character from the repeating sequence. The generator expression selects the pair of next keyword letter and text character if the text character is alphabetic, else it just selects the non-alphabetic character alone.

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

Sidebar

Related Questions

i am stuck with this small problem in my code. I am trying to
Sometimes I still get stuck trying to translate procedural code into functional code. Is
I've been stuck trying to arrive at a best solution for this for a
I'm kind of like stuck trying to implement YUI autocomplete textbox. here's the code:
Really stuck on trying to write code to unzip a file or directory on
I'm feeling lost as to how to do this. I am trying to perform
I'm trying to write a custom Rake task to perform some tests for a
This may be an easy question, but I'm stuck. I am trying to implement
Ok, I'm trying to code a basic program that could help user to find
I am trying to perform the following tasks with files, but I am stuck.

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.