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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:53:44+00:00 2026-06-08T07:53:44+00:00

Take for example a short file consisting of these lines: Apple = 1 Pear

  • 0

Take for example a short file consisting of these lines:

Apple = 1
Pear = 1
Orange = 2
;
Orange = 3
Pear = 1
;
Apple = 1
Pear = 1
Orange = 1

What I did was to readline the text file, and put Apple, Orange and Pear into their respective lists such as:

Orange = [ 2,3,1 ]
Pear = [ 1,1,1 ]

I used line.count('Apple')==1 to identify that the current line in the text file is a fruit and then append the value after = to the list.

As you can see, the second section is missing Apple. I want the list to be:

Apple = [ 1,'-',1]

Whenever the line does not show a fruit, the list should append - to indicate it.

My question is, how then can I do it ie. to determine that a section is missing a fruit name and then to append - to it.

  • 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-08T07:53:47+00:00Added an answer on June 8, 2026 at 7:53 am

    You could keep an array with all the fruit names found in a section. When you encounter a semicolon you check for each fruit if its name exists in the array and append a ‘-‘ if it does not, then you clear the array and continue with the next section.

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

Sidebar

Related Questions

example some array {2,8,9,10,21,32,1,6,3...} first child take (data size / 2) and sort second
Take this example: {-# OPTIONS_HADDOCK ignore-exports #-} module HaddockTest (e1) where -- * Exported
Take for example the python built in pow() function. xs = [1,2,3,4,5,6,7,8] from functools
Take for example this table (let's call it BIN_TABLE ): +------+------+ | A |
Take this example code (ignore it being horribly inefficient for the moment) let listToString
Take for example an application which has users, each of which can be in
Take for example the following regex match. preg_match('!^publisher/([A-Za-z0-9\-\_]+)/([0-9]+)/([0-9]{4})-(january|february|march|april|may|june|july|august|september|october|november|december):([0-9]{1,2})-([0-9]{1,2})/([A-Za-z0-9\-\_]+)/([0-9]+)(/page-[0-9]+)?$!', 'publisher/news/1/2010-march:03-23/test_title/1/page-1', $matches); print_r($matches); It produces the
Take the example I have setup at http://jsfiddle.net/vEF6y/ Click on the 'add item' button
Take this example Proc: proc = Proc.new {|x,y,&block| block.call(x,y,self.instance_method)} It takes two arguments, x
I take an example from Fortran 95/2003 explained by Metcalf et al, since m

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.