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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:38:09+00:00 2026-05-27T05:38:09+00:00

I am stuck with the logic here… i have to extract some values from

  • 0

I am stuck with the logic here… i have to extract some values from a text file that looks like this

AAA
+-------------+------------------+
|          ID |            count |
+-------------+------------------+
|           3 |             1445 |
|           4 |              105 |
|           9 |              160 |
|          10 |               30 |
+-------------+------------------+
BBB
+-------------+------------------+
|          ID |            count |
+-------------+------------------+
|           3 |             1445 |
|           4 |              105 |
|           9 |              160 |
|          10 |               30 |
+-------------+------------------+
CCC
+-------------+------------------+
|          ID |            count |
+-------------+------------------+
|           3 |             1445 |
|           4 |              105 |
|           9 |              160 |
|          10 |               30 |
+-------------+------------------+

I am not able to extract value from BBB alone and append it to a list like

f = open(sys.argv[1], "r")
text = f.readlines()
B_Values = []
for i in text:
    if i.startswith("BBB"):(Example)
       B_Values.append("only values of BBB")
    if i.startswith("CCC"):
       break

print B_Values

should result

['|           3 |             1445 |','|           4 |              105 |','|           9 |              160 |','|          10 |               30 |']
  • 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-27T05:38:10+00:00Added an answer on May 27, 2026 at 5:38 am
    d = {}
    with open(sys.argv[1]) as f:
        for line in f:
            if line[0].isalpha(): # is first character in the line a letter?
                curr = d.setdefault(line.strip(), [])
            elif filter(str.isdigit, line): # is there any digit in the line?
                curr.append(line.strip())
    

    for this file, d is now:

    {'AAA': ['|           3 |             1445 |',
             '|           4 |              105 |',
             '|           9 |              160 |',
             '|          10 |               30 |'],
     'BBB': ['|           3 |             1445 |',
             '|           4 |              105 |',
             '|           9 |              160 |',
             '|          10 |               30 |'],
     'CCC': ['|           3 |             1445 |',
             '|           4 |              105 |',
             '|           9 |              160 |',
             '|          10 |               30 |']}
    

    Your B_values are d['BBB']

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

Sidebar

Related Questions

I have a method like this: def foo(fruit='apple', cut=sliced, topping=ice cream) # some logic
I have some controller logic: public function seafood() { $this->set('title', 'Seafood restaurants in and
Kinda stuck here... I have an application with lets say 5000 rows of data
I'm a bit stuck on this. Basically I want to do something like the
I am stuck in a frustrating rut here. I have an authentication system (built
I am stuck with a logic problem here. I did a lot of thinking
A php student here that has been stuck for many hours now :( Here's
I am using a book to study, and am stuck here If you have
I need some help figuring out this for loop logic. I know exactly what
I prefer to have the exception handling logic further up in the call stack,

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.