#๐Ÿ”’ Trying to clean up some code by turning three operations into a range(3) loop.

22 messages ยท Page 1 of 1 (latest)

twilit terrace
#

https://paste.pythondiscord.com/PFXQ

Hit the char limit and had to put it in a link.

In my mind if I can find a way to generate these outputs in a loop then I can just sub in those for my array indexes and crunch all of this into a singe loop:

when i = 0
then
x = 0
y = 1

when i = 1
then
x = 0
y = 2

when i = 2
then
x = 1
y = 2
for i in range(3):
if "99" not in [sorted_game[x][0], sorted_game[y][0]]:
  score = data["diffs"][f"{sorted_game[x][0]}_{sorted_game[y][0]}"]
  if score > 0:
    msg = f"{msg}\n{score} for {friends[sorted_game[x][0]]} vs    {friends[sorted_game[y][0]]}"
  else:
    msg = f"{msg}\n{abs(score)} for {friends[sorted_game[y][0]]} vs     {friends[sorted_game[x][0]]}"

Any ideas?

stiff pewterBOT
#

@twilit terrace

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

sage atlas
candid sinew
#

sounds more like a dictionary problem than a loop problem pithink

twilit terrace
#

Unless I am missing something I do not think so. but when i think about it I may be able to rearrange this then use boolean (wrong word for this i think but just on/off logic shifted left).

so the output is

i = 0 ; 0 1
i = 1 ; 1 2
i = 2 ; 0 1
#

since now I am just flipping back then forth

candid sinew
#

!e

i = {
    0: (0, 1),
    1: (1, 2),
    2: (0, 1),
}

print(i[0])
print(i[1])
print(i[2])
stiff pewterBOT
#

@candid sinew :white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | (0, 1)
002 | (1, 2)
003 | (0, 1)
twilit terrace
#

hmmmm, nifty

#

I was trying to think of it in the sense of a little logical test in each loop, but a lookup just solves it all

candid sinew
#

jup

sage atlas
#

is it always "even numbers are 0, 1" and "odd numbers are 1, 2"?

twilit terrace
#

ty and I can even store that lookup in the json that I am loading in anyways

candid sinew
#

better even

sage atlas
#

yeah, seems a lot more straightforward than having a lookup

twilit terrace
#

I may be overlooking something with how I rearragned things. If I cannot swap around the run order I can go with the dreammaster solution, if I can then fashoomps

#

thank you both btw @sage atlas @candid sinew ๐Ÿซ‚

#

!close

stiff pewterBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.