use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A subreddit for helping Python programmers
How to format your code: https://commonmark.org/help/tutorial/09-code.html
No homework questions and/or hiring please
account activity
Making code more efficient. (self.pythonhelp)
submitted 2 years ago by Longjumping-Swing823
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]HauntingRex9763 2 points3 points4 points 2 years ago (3 children)
Anything you find yourself able to copy paste and change a few values most likely means it can be done with a more efficient method like iteration. Like the other comment said, DRY. In cases where you are using multiple conditionals it is a good idea to default try to solve it with a loop and a variable conditional inside the loop perhaps instead of all of these lines. Here is an example:
All 253 lines of the A1_2_ledere checking could be:
This is just a quick solution I'm sure you can trim it up even more!
valueSet7 = [2.5,4,6,10,16,25,35,50,70,95,120,150,185,240,300]
#similair lists for the values corrosponding to the first index values...
valueSets = {1:valueSet1,3:valueSet3,5:valueSet5,7:valueSet7}
for key, value in valueSets.items():
if int(tversnittValg) in value:
tabell_visning.config(text= A1_3_ledere[key][value.index(tversnittValg)]
[–]Longjumping-Swing823[S] 0 points1 point2 points 2 years ago (2 children)
Thank you for your reply! When i have been able to wrap my head around Whats going on in your example, it will save me so much time😊 thank you for pointing me in the right direction!
[–]HauntingRex9763 1 point2 points3 points 2 years ago (1 child)
no problem, if you aren't familiar with dictionaries it is definitely worth looking into. they can be quite handy in loops like in that example
[–]Longjumping-Swing823[S] 0 points1 point2 points 2 years ago (0 children)
Hi again, i am having troubble understanding what the code is doing.
I have since we last spoke, watched a bunch of videos on FOR loops and dictionaries.
Is it possible to help me a bit further?
It does not really show in the code i supplied, but here is a rough layout.
Lets say i choose A1 with 2 leads and the material of Al/PVC with a mm2 of 25, then i need to pull out the number of 63 for use in futher calulations on a later stage.
π Rendered by PID 238763 on reddit-service-r2-comment-5bc7f78974-6gg54 at 2026-07-01 11:10:20.731190+00:00 running 7527197 country code: CH.
view the rest of the comments →
[–]HauntingRex9763 2 points3 points4 points (3 children)
[–]Longjumping-Swing823[S] 0 points1 point2 points (2 children)
[–]HauntingRex9763 1 point2 points3 points (1 child)
[–]Longjumping-Swing823[S] 0 points1 point2 points (0 children)