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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:01:15+00:00 2026-06-12T15:01:15+00:00

I write this code: f = open(‘example.txt’,’r’) lines = f.readlines() for i, line in

  • 0

I write this code:

f = open('example.txt','r')
lines = f.readlines()

for i, line in enumerate(f):
if i < 3:
   lines = ['LC '+line for line in lines]
   with open('./example.txt', 'w') as f:
      f.writelines(lines)
      f.close()
elif i < 5:
    lines = ['LB '+line for line in lines]
    with open('./example.txt', 'w') as f:
        f.writelines(lines)
        f.close()
elif i > 6:
    break

 f.close()

I have a file with 11 lines. I want to write something in the start from every line. The word is different for the 3 first line and different for other 2. Could you help me what am I doing wrong?

  • 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-12T15:01:16+00:00Added an answer on June 12, 2026 at 3:01 pm
    lines = [("LC" if i < 3 else "LB")+line for i,line in enumerate(lines)]
    

    might do the trick

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

Sidebar

Related Questions

this is my code: f = open('text/a.log', 'wb') f.write('hahaha') f.close() and it is not
Using this code import re file = open('FilePath/OUTPUT.01') lines = file.read() file.close() for match
When I run this code in irb: File.open('j1.txt','w') {|f| f.write(doc1223423)} it works successfully. But
f = open(go.txt, w) f.write(title) f.close() What if title is in japanese/utf-8? How do
I have this code FileStream fs = new FileStream(Scores.txt, FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw =
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
I write this code to get Dunnet anova post hoc test import rpy2.robjects as
i write this code in main.java ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); try{ HttpClient httpclient
I have write this code but it does work only if I am already
I've write this code to add textview into table row, but I've problem for

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.