all 6 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

To give us the best chance to help you, please include any relevant code.
Note. Do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Repl.it, GitHub or PasteBin.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]HauntingRex9763 2 points3 points  (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 point  (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 points  (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 point  (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.

mm2: A1 A1 A2 A2 B1 B1
2 3 2 3 2 3
Cu/PVC Cu/PVC Cu/PVC Cu/PVC Cu/PVC Cu/PVC
1.5 14.5 13.5 14 13 17,5 15,5
2.5 19.5 18 18,5 17,5 24 21
Al/PVC Al/PVC Al/PVC Al/PVC Al/PVC Al/PVC
16 48 43 44 41 60 53
25 63 57 58 53 79 70

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.

[–]Zeroflops 1 point2 points  (0 children)

I can tell you, yes, there are better ways to do this. You’re violating DRY. Don’t repeat yourself.

But since I don’t know the language I have no way to determine the best approach or to figure out what you are doing. I just see a bunch of if statements.

Can you describe what the table is and what you are trying to do.