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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:25:29+00:00 2026-05-28T08:25:29+00:00

I need to create a function that can takes a list of tuples and

  • 0

I need to create a function that can takes a list of tuples and a number. Example:
if the list of tuples is [(2,5),(8,9),(11,19),(22,43),(47,50)], and the number is 14, the it should return 18.
The reason for this is at number 13 in the list 2,3,4,5,8,9,11,12,13,14,15,16,17,18,19... is 18 if all numbers are included:

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18.

I now have:

def converting(tuples,index):
    values = [] #I will get [(2,3,4,5,6),(8,9),(11,12,13,14,15,16,17,18,19),(22,..,43),(47,48,49,50)]
    for tuple in tuples: 
        tupleValues = range(tuple[0], tuple[1]+1)
        values.extend(tupleValues)  #ex(2,3,4,5,6)
    if index <= len(values): #If 14 in the example is lower than len of the list, eg 42
        return values[index-1] #return value of 14-1, which is 16?
print converting(14,[(2,5),(8,9),(11,19),(22,43),(47,50)])

When I print this I get the message:
for tuple in tuples:
TypeError: ‘int’ object is not iterable

  • 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-28T08:25:30+00:00Added an answer on May 28, 2026 at 8:25 am

    If I understand the problem correctly, you have a sequence of intervals and you need to extract the n-th number from those intervals. Here is a different solution regarding the algorithm used. Just count all the missing numbers from your interval sequence and add it to your value:

    tuples = [(2,5),(8,9),(11,19),(22,43),(47,50)]
    #tuples = [(2,7),(9,14),(17,20)]
    
    def result(tuple, value):
        start = tuples[0][0] - 1
        for idx in range(len(tuples) - 1):
            if tuples[idx][1] >= value + start:
                break
            start = start + (tuples[idx+1][0] - tuples[idx][1] - 1)  
        return value + start  
    
    for i in range(1, 16):
        print str(i) + ' ' + str(result(tuples, i))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a function that uses a loop. This function will open
I need to create a VB.NET function that takes the source code of a
I need to create a javascript function that checks if it has been a
I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
I have a function that takes a string object name and I need the
I would like to create a function in C# that takes a specific webpage
I need to run a function that takes two arguments several times. I have
I have a table-value function that takes an ID number of a person and
i need to create a function in my application to set its available memory
I need to create a php search function for names and need to change

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.