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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:47:20+00:00 2026-06-09T01:47:20+00:00

I have a nested list which contains an integer as the last element of

  • 0

I have a nested list which contains an integer as the last element of each list, and I am trying to see if the next item in the list is one more than the current item, i.e. if the last element of the current list is 104, if the last element of the next list is 105, do something.

data=[[a,b,c,1200],[a,g,x,3401],[f,a,c,3402],[f,a,c,3403]etc]
for item in data:
    if next(item[-1])==item[-1]+1: #if next item is this item plus one
        #do something

This keeps raising TypeError: Can't convert 'int' object to str implicitly and I don’t know why. Is there a way to use addition to compare list elements in python that I’m not aware of?

(The next(item) part might not be accurate, as I’m using a function to get previous and next items in the full code, not next(), but it is the same in principle)

  • 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-06-09T01:47:21+00:00Added an answer on June 9, 2026 at 1:47 am

    This will do what you want.

    data=[[a,b,c,1200],[a,g,x,3401],[f,a,c,3402],[f,a,c,3403]etc]
    previous = 0 # adjust if necessary
    for item in data:
        if item[-1] == previous + 1:
            #do something
        previous = item[-1]
    

    next(item[-1]) does not do what you think. You can deduce this yourself by applying some reasoning:

    1. next(), doesn’t receive the actual precursor to the “next” element that you want, that would be item
    2. if you were to pass item, next() would have to figure out what list item is part of.
    3. What if item is in multiple lists? What if it occurs multiple times in the same list? Which item to return?

    As you can see, there is no possible way to get the next item in a list by simply passing it some random object that happens to be part of some list.

    What next() actually does is quite different. It gives you the next item produced from an iterator/generator.

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

Sidebar

Related Questions

I have a series of nested TableLayoutPanel controls which each of them contains lots
I have a list which contains a number of _MEMORY_BASIC_INFORMATION structs nested within mb
I have an application which contains a nested list box, that is a list
I have a nested oredered list which i m animating using this code... var
I have a nested drag and drop list which return json formattet string. I
I have a list which have divs inside it.. Now when i use nested
I have a nested list comprising ~30,000 sub-lists, each with three entries, e.g., nested_list
I have Python nested list that I'm trying to organize and eventually count number
I have the following List which contains the following collection. How i can transform
I have a table which contains a list of categories and and another table

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.