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

  • Home
  • SEARCH
  • 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 3613958
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:11:19+00:00 2026-05-18T22:11:19+00:00

One of the practices I have gotten into in Python from the beginning is

  • 0

One of the practices I have gotten into in Python from the beginning is to reduce the number of variables I create as compared to the number I would create when trying to do the same thing in SAS or Fortran

for example here is some code I wrote tonight:

def idMissingFilings(dEFilings,indexFilings):
    inBoth=set(indexFilings.keys()).intersection(dEFilings.keys())
    missingFromDE=[]
    for each in inBoth:
        if len(dEFilings[each])<len(indexFilings[each]):

            dEtemp=[]
            for filing in dEFilings[each]:
                #dateText=filing.split("\\")[-1].split('-')[0]
                #year=dateText[0:5]
                #month=dateText[5:7]
                #day=dateText[7:]
                #dETemp.append(year+"-"+month+"-"+day+"-"+filing[-2:])    
            dEtemp.append(filing.split('\\')[-1].split('-')[0][1:5]+"-"+filing.split('\\')[-1].split('-')[0][5:7]+"-"+filing.split('\\')[-1].split('-')[0][7:]+"-"+filing[-2:])
            indexTemp=[]
            for infiling in indexFilings[each]:
                indexTemp.append(infiling.split('|')[3]+"-"+infiling[-6:-4])
            tempMissing=set(indexTemp).difference(dEtemp)
            for infiling in indexFilings[each]:
                if infiling.split('|')[3]+"-"+infiling[-6:-4] in tempMissing:
                    missingFromDE.append(infiling)
    return missingFromDE

Now I split one of the strings I am processing 4 times in the line dEtemp.append(blah blah blah)

filing.split('\\')

Historically in Fortran or SAS if I were to attempt the same I would have ‘sliced’ my string once and assigned a variable to each part of the string that I was going to use in this expression.

I am constantly forcing myself to use expressions instead of first resolving to a value and using the value. The only reason I do this is that I am learning by mimicking other people’s code but it has been in the back of my mind to ask this question – where can I find a cogent discussion of why one is better than the other

The code compares a set of documents on a drive and a source list of those documents and checks to see whether all of those from the source are represented on the drive

Okay the commented section is much easier to read and how I decided to respond to nosklos answer

  • 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-18T22:11:20+00:00Added an answer on May 18, 2026 at 10:11 pm

    Yeah, it is not better to put everything in the expression. Please use variables.

    Using variables is not only better because you will do the operation only once and save the value for multiple uses. The main reason is that code becomes more readable that way. If you name the variable right, it doubles as free implicit documentation!

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

Sidebar

Related Questions

I have a question about best practices regarding how one should approach storing complex
Is it good practice to have more than one try{} catch{} statement per method?
Are there good reasons why it's a better practice to have only one return
I am looking for one or more resources on best practices for c# codegen
Why is it bad practice to declare variables on one line? e.g. private String
I have a script that appends some rows to a table. One of the
We manage a site for a medical charity. They have a number of links
One of the best practice is accessing data via stored procedures. I understand why
Are modal windows/dialogs considered a good practice for websites? One of the things that
One of those classic programming interview questions... You are given two marbles, and told

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.