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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:09:26+00:00 2026-05-31T19:09:26+00:00

I have a list and I want to extract to another list the data

  • 0

I have a list and I want to extract to another list the data that exist between top_row and bottom_row.
I know the top_row and also that the bottom_row corresponds to data[0] = last integer data (next row is made of strings, but there are also rows with integers which I’m not interested).

I’ve tried several things, but w/o success:

for row,data in enumerate(fileData):
    if row > row_elements: #top_row
        try:
            n = int(data[0])
            aux = True
        except:
            n = 0
        while aux: #until it finds the bottom_row
            elements.append(data)

The problem is that it never iterates the second row, if I replace while with if I get all rows which the first column is an integer.

fileData is like:

*Element, type=B31H
  1,   1,   2
  2,   2,   3
  .
  .
  .
 359, 374, 375
 360, 375, 376
*Elset, elset=PART-1-1_LEDGER-1-LIN-1-2-RAD-2__PICKEDSET2, generate

I’m only interested in rows with first column values equal to 1 to 360.

Many 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-31T19:09:27+00:00Added an answer on May 31, 2026 at 7:09 pm

    If no exception is thrown in the try part, then you basically end up with an endless loop, given that aux will always be True.

    I’m not perfectly sure what you are doing in your code, given the way the data looks isn’t clear and some things are not used (like n?), but in general, you can stop a running loop (both for and while loops) with the break statement:

    for row, data in enumerate(fileData):
        if conditionToAbortTheLoop:
            break
    

    So in your case, I would guess something like this would work:

    for row, data in enumerate(fileData):
        if row > row_elements: # below `top_row`
            try:
                int(data[0])
            except ValueError:
                break # not an int value, `bottom_row` found
    
            # if we get here, we’re between the top- and bottom row.
            elements.append(data)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a List of 5 items. I want to extract the last item,
If you have a list in python, and want to extract elements at indices
I have a list that I want to loop through (for trimtemp in trim)
I have one list that I want to take a slice of, reverse that
I have 2 list and i want to add a class =last to the
I have a list that I want to put in a dictionary, for simplicity
I have list of structure. I want to modify a particular data from the
i have list of rows that user select and i want to delete them,
I have some package of javadoc, and I want to extract a list of
I have a list of 50 items and I want to extract some other

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.