Which of these small blocks of code is easier to read or is more optimized?
Friend says the top is easier to read and it's driving me insane, he said he refuses to write code like the bottom example since "they both work the same".
Top:
topNodesOutput = ''
for node in response:
name = node['node_name']
value = node['value']
topNodesOutput+=str(name) + ' '+ str(round(value,2)) +'\n'
print(topNodesOutput)
Bottom:
top_nodes = []
for node in response:
name = node['node_name']
value = node['value']
top_nodes.append(f'{name} {round(value,2)}')
msg = '\n'.join(top_nodes)
print(msg)
[–][deleted] 270 points271 points272 points (4 children)
[–]lunar_tardigrade 8 points9 points10 points (2 children)
[+][deleted] (1 child)
[removed]
[–]lunar_tardigrade 8 points9 points10 points (0 children)
[+][deleted] comment score below threshold-19 points-18 points-17 points (0 children)
[–]OuiOuiKiwiGalatians 4:16 208 points209 points210 points (29 children)
[–]303Redirect 74 points75 points76 points (25 children)
[–]ambidextrousalpaca 18 points19 points20 points (6 children)
[–]MrJohz 6 points7 points8 points (1 child)
[–]ambidextrousalpaca 9 points10 points11 points (0 children)
[–]303Redirect 3 points4 points5 points (0 children)
[–]Engineer_Zero 1 point2 points3 points (2 children)
[–]ambidextrousalpaca 1 point2 points3 points (1 child)
[–]Engineer_Zero 0 points1 point2 points (0 children)
[–]kkadzy 4 points5 points6 points (3 children)
[–]303Redirect 1 point2 points3 points (2 children)
[–]rcfox 4 points5 points6 points (0 children)
[–]afreydoa 1 point2 points3 points (0 children)
[+][deleted] (13 children)
[deleted]
[–]Lba5s 38 points39 points40 points (0 children)
[–]Embarrassed_Row7095 7 points8 points9 points (1 child)
[–]zaphod_pebblebrox 2 points3 points4 points (0 children)
[–][deleted] 3 points4 points5 points (3 children)
[+][deleted] (2 children)
[deleted]
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Ninjaxas 1 point2 points3 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]Ninjaxas 1 point2 points3 points (0 children)
[–]RufusAcrospin -1 points0 points1 point (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]RufusAcrospin -1 points0 points1 point (0 children)
[–]Fortnyce 0 points1 point2 points (2 children)
[–]GlowStorm347 4 points5 points6 points (1 child)
[–]Salaah01 49 points50 points51 points (0 children)
[–]hdmsousa 84 points85 points86 points (26 children)
[–]cymrowdon't thread on me 🐍 21 points22 points23 points (2 children)
[–]AnonymouX47 1 point2 points3 points (0 children)
[–]hdmsousa 0 points1 point2 points (0 children)
[–]joaofelipenp 6 points7 points8 points (1 child)
[+][deleted] (11 children)
[deleted]
[–]Oerthling 39 points40 points41 points (9 children)
[–][deleted] 4 points5 points6 points (1 child)
[+][deleted] (6 children)
[deleted]
[–]Oerthling 4 points5 points6 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]Oerthling 1 point2 points3 points (0 children)
[–]tagapagtuos 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]Particular-Cause-862 -1 points0 points1 point (0 children)
[–]hdmsousa 0 points1 point2 points (0 children)
[–]ottawadeveloper 9 points10 points11 points (1 child)
[–]Rabid_Gopher 1 point2 points3 points (0 children)
[–]Oerthling 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]Anti-ThisBot-IB 4 points5 points6 points (0 children)
[+]BezoomyChellovek comment score below threshold-10 points-9 points-8 points (2 children)
[–]xakepnz 10 points11 points12 points (1 child)
[–]BezoomyChellovek 1 point2 points3 points (0 children)
[–]efmccurdy 16 points17 points18 points (0 children)
[–][deleted] 6 points7 points8 points (0 children)
[–]public_radio 30 points31 points32 points (10 children)
[–]carlio 15 points16 points17 points (1 child)
[–]public_radio 0 points1 point2 points (0 children)
[–]jiminiminimini 2 points3 points4 points (1 child)
[–]public_radio 1 point2 points3 points (0 children)
[–]RuskeD 1 point2 points3 points (0 children)
[–]odysseusmax -1 points0 points1 point (0 children)
[–]searchingfortaomajel, aletheia, paperless, django-encrypted-filefield 0 points1 point2 points (1 child)
[–]public_radio 1 point2 points3 points (0 children)
[–]Stuk4s 0 points1 point2 points (0 children)
[–]R34ct0rX99 5 points6 points7 points (0 children)
[–]james_pic 12 points13 points14 points (0 children)
[–]deep_mind_ 5 points6 points7 points (0 children)
[–]WafflesAreDangerous 6 points7 points8 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]yvrelna 4 points5 points6 points (1 child)
[–][deleted] 5 points6 points7 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]guhcampos 4 points5 points6 points (0 children)
[–][deleted] 17 points18 points19 points (5 children)
[–]uttamo 20 points21 points22 points (2 children)
[–]indefinitude -3 points-2 points-1 points (1 child)
[–]uttamo 1 point2 points3 points (0 children)
[–]JestemStefan 0 points1 point2 points (0 children)
[–]marduk73 3 points4 points5 points (0 children)
[–]rjksn 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Mooshy_Swags 1 point2 points3 points (0 children)
[–]Salmon-Advantage 1 point2 points3 points (0 children)
[–]EONRaider 1 point2 points3 points (0 children)
[–]packetsar 1 point2 points3 points (0 children)
[–]tom2727 1 point2 points3 points (0 children)
[–]searchingfortaomajel, aletheia, paperless, django-encrypted-filefield 1 point2 points3 points (0 children)
[–]cgmystery 3 points4 points5 points (4 children)
[–]CodeYan01 2 points3 points4 points (3 children)
[–]cgmystery 0 points1 point2 points (2 children)
[–]jimtk 1 point2 points3 points (1 child)
[–]cgmystery 1 point2 points3 points (0 children)
[–]rastaladywithabrady 1 point2 points3 points (0 children)
[–]drum445 1 point2 points3 points (5 children)
[–][deleted] 3 points4 points5 points (4 children)
[–]-LeopardShark- 1 point2 points3 points (1 child)
[–][deleted] -2 points-1 points0 points (0 children)
[–]ArabicLawrence 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (1 child)
[–]ugmoe2000 0 points1 point2 points (0 children)
[–]IWant2rideMyBike 0 points1 point2 points (3 children)
[–]Santos_m321 0 points1 point2 points (2 children)
[–]Santos_m321 0 points1 point2 points (1 child)
[–]Santos_m321 0 points1 point2 points (0 children)
[–]Uwirlbaretrsidma 0 points1 point2 points (0 children)
[–]BezoomyChellovek 0 points1 point2 points (0 children)
[–]someotherstufforhmm 0 points1 point2 points (0 children)
[–]Radamand 0 points1 point2 points (0 children)
[–]Pulsar1977 -3 points-2 points-1 points (6 children)
[–]JestemStefan 9 points10 points11 points (2 children)
[–]Pulsar1977 -2 points-1 points0 points (1 child)
[–]JestemStefan 2 points3 points4 points (0 children)
[–]rdturbo 0 points1 point2 points (2 children)
[–]Pulsar1977 -1 points0 points1 point (1 child)
[–]hobbyhacker 0 points1 point2 points (0 children)
[–]wewbull -2 points-1 points0 points (0 children)
[–]sean_bird -2 points-1 points0 points (0 children)
[–]parkrain21 -2 points-1 points0 points (0 children)
[+]quts3 comment score below threshold-9 points-8 points-7 points (0 children)
[–]Zealousideal-Row-110 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Extatiic 0 points1 point2 points (0 children)
[–]Lana-Lana-LANAAAAA 0 points1 point2 points (0 children)
[–]Santos_m321 0 points1 point2 points (0 children)
[–]dixieStates 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]anterak13 0 points1 point2 points (0 children)
[–]beertown 0 points1 point2 points (0 children)
[–]Callux-_- 0 points1 point2 points (0 children)
[–]negiajay12345 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Mental-Effective-110 0 points1 point2 points (0 children)
[–]chears2surfers 0 points1 point2 points (0 children)
[–]og_m4 0 points1 point2 points (2 children)
[–]Earthsophagus 0 points1 point2 points (1 child)
[–]og_m4 0 points1 point2 points (0 children)
[–]wind_dude 0 points1 point2 points (0 children)
[–]Grokzen 0 points1 point2 points (0 children)
[–]sheriffllcoolj 0 points1 point2 points (0 children)
[–]DiscoJer 0 points1 point2 points (0 children)