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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:25:36+00:00 2026-05-15T10:25:36+00:00

i understand that the code given below will not be compltely understood unless i

  • 0

i understand that the code given below will not be compltely understood unless i explain my whole of previous and next lines of code.
But this is part of the code which is causing so much of delay in my project and want to optimize this.
i want to know which code part is faulty and how could this be replaced.
i guess,few can say that use of this function is heavy compared and other ligher method are available to do this work

please help,

thanks in advance

for i in range(len(lists)):
    save=database_index[lists[i]]
    #print save
    #if save[1]!='text0194'and save[1]!='text0526':
    using_data[save[0]]=save
    p=os.path.join("c:/begpython/wavnk/",str(str(str(save[1]).replace('phone','text'))+'.pm'))
    x1=open(p , 'r')
    x2=open(p ,'r')
    for i in range(6):
        x1.readline()
        x2.readline()
    gen = (float(line.partition(' ')[0]) for line in x1)
    r= min(enumerate(gen), key=lambda x: abs(x[1] - float(save[4])))
    #print r[0]
    a1=linecache.getline(str(str(p).replace('.pm','.mcep')), (r[0]+1))
    #print a1
    p1=str(str(a1).rstrip('\n')).split(' ')
    #print p1
    join_cost_index_end[save[0]]=p1
    #print join_cost_index_end

    gen = (float(line.partition(' ')[0]) for line in x2)
    r= min(enumerate(gen), key=lambda x: abs(x[1] - float(save[3])))
    #print r[0]
    a2=linecache.getline(str(str(p).replace('.pm','.mcep')), (r[0]+1))
    #print a2
    p2=str(str(a2).rstrip('\n')).split(' ')
    #print p2
    join_cost_index_strt[save[0]]=p2
    #print join_cost_index_strt
    j=j+1

    #print j
    #print join_cost_index_end
    #print join_cost_index_strt
    enter code here

here my database_index has about 2,50,000 entries`

  • 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-15T10:25:37+00:00Added an answer on May 15, 2026 at 10:25 am
    def get_list(file, cmp, fout):
        ind, _ = min(enumerate(file), key=lambda x: abs(x[1] - cmp))
        return fout[ind].rstrip('\n').split(' ')
    
    root = r'c:\begpython\wavnk'
    header = 6
    for lst in lists:
        save = database_index[lst]
        index, base, _, abs2, abs1, *_ = save
        using_data[index] = save
    
        base = os.path.join(root, base.replace('phone', 'text'))
        fin, fout = base + '.pm', base + '.mcep'
        file = open(fin)
        fout = open(fout).readlines()
        [next(file) for _ in range(header)]
        file = [float(line.partition(' ')[0]) for line in file]
        join_cost_index_end[index] = get_list(file, float(abs1), fout)
        join_cost_index_strt[index] = get_list(file, float(abs2), fout)
    

    Don’t:

    1. convert string to string multiple times, it’ll remain a string
    2. convert value within loop when it could be done outside the loop
    3. use single-letter for meaning variables
    4. iterate over sequences with range(len(sequence))
    5. copy-paste bits of code: use functions
    6. use any code without reading docs first
    7. rely on SO for psychic debugging.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 423k
  • Answers 423k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It simply demonstrates that analyzing language behavior by "trying it… May 15, 2026 at 11:46 am
  • Editorial Team
    Editorial Team added an answer Don't call it SURROGATE_KEY. That is meaningless in any other… May 15, 2026 at 11:46 am
  • Editorial Team
    Editorial Team added an answer I'm guessing you're referring to the .NET Micro Framework. You're… May 15, 2026 at 11:46 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.