Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looking for a more optimized approach (Python) #1

Open
seanpm2001 opened this issue Dec 30, 2020 · 5 comments
Open

Looking for a more optimized approach (Python) #1

seanpm2001 opened this issue Dec 30, 2020 · 5 comments
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested

Comments

@seanpm2001
Copy link
Owner


Looking for a more optimized approach (Python)

I gave up early on on the original Advanced Eye Chart script due to its over complexity. I know it can be done in a much more efficient way, I just don't know what. I have been trying to find a new efficient way for nearly 48 hours.

Here is the old, incomplete, inefficient code

# This is extremely inefficient. If anyone knows a better way, let me know
letter1ID = random.randint(0, 85) # First letter on the chart, top left, largest (200/20)
if (letter1ID == 0):
	letter1 = str("a")
if (letter1ID == 1):
	letter1 = str("A")
if (letter1ID == 2):
	letter1 = str("b")
if (letter1ID == 3):
	letter1 = str("B")
if (letter1ID == 4):
	letter1 = str("c")
if (letter1ID == 5):
	letter1 = str("C")
if (letter1ID == 6):
	letter1 = str("d")
if (letter1ID == 7):
	letter1 = str("D")
if (letter1ID == 8):
	letter1 = str("e")
if (letter1ID == 9):
	letter1 = str("E")
if (letter1ID == 10):
	letter1 = str("f")
if (letter1ID == 11):
	letter1 = str("F")
if (letter1ID == 12):
	letter1 = str("g")
if (letter1ID == 13):
	letter1 = str("G")
if (letter1ID == 14):
	letter1 = str("h")
if (letter1ID == 15):
	letter1 = str("H")
if (letter1ID == 16):
	letter1 = str("i")
if (letter1ID == 17):
	letter1 = str("I")
if (letter1ID == 18):
	letter1 = str("j")
if (letter1ID == 19):
	letter1 = str("J")
if (letter1ID == 20):
	letter1 = str("k")
if (letter1ID == 21):
	letter1 = str("K")
if (letter1ID == 22):
	letter1 = str("l")
if (letter1ID == 23):
	letter1 = str("L")
if (letter1ID == 24):
	letter1 = str("m")
if (letter1ID == 25):
	letter1 = str("M")
if (letter1ID == 26):
	letter1 = str("n")
if (letter1ID == 27):
	letter1 = str("N")
if (letter1ID == 28):
	letter1 = str("o")
if (letter1ID == 29):
	letter1 = str("O")
if (letter1ID == 30):
	letter1 = str("p")
if (letter1ID == 31):
	letter1 = str("P")
if (letter1ID == 32):
	letter1 = str("q")
if (letter1ID == 33):
	letter1 = str("Q")
if (letter1ID == 34):
	letter1 = str("r")
if (letter1ID == 35):
	letter1 = str("R")
if (letter1ID == 36):
	letter1 = str("s")
if (letter1ID == 37):
	letter1 = str("S")
if (letter1ID == 38):
	letter1 = str("T")
if (letter1ID == 39):
	letter1 = str("t")
if (letter1ID == 40):
	letter1 = str("u")
if (letter1ID == 41):
	letter1 = str("U")
if (letter1ID == 42):
	letter1 = str("v")
if (letter1ID == 43):
	letter1 = str("V")
if (letter1ID == 44):
	letter1 = str("w")
if (letter1ID == 45):
	letter1 = str("W")
if (letter1ID == 46):
	letter1 = str("x")
if (letter1ID == 47):
	letter1 = str("X")
if (letter1ID == 48):
	letter1 = str("y")
if (letter1ID == 49):
	letter1 = str("Y")
if (letter1ID == 50):
	letter1 = str("z")
if (letter1ID == 51):
	letter1 = str("Z")
if (letter1ID == 52):
	letter1 = str("0")
if (letter1ID == 53):
	letter1 = str("1")
if (letter1ID == 54):
	letter1 = str("2")
if (letter1ID == 55):
	letter1 = str("3")
if (letter1ID == 56):
	letter1 = str("4")
if (letter1ID == 57):
	letter1 = str("5")
if (letter1ID == 58):
	letter1 = str("6")
if (letter1ID == 59):
	letter1 = str("7")
if (letter1ID == 60):
	letter1 = str("8")
if (letter1ID == 61):
	letter1 = str("9")
if (letter1ID == 62):
	letter1 = str(",")
if (letter1ID == 63):
	letter1 = str(".")
if (letter1ID == 64):
	letter1 = str("!")
if (letter1ID == 65):
	letter1 = str("@")
if (letter1ID == 66):
	letter1 = str("#")
if (letter1ID == 67):
	letter1 = str("$")
if (letter1ID == 68):
	letter1 = str("!")
if (letter1ID == 69):
	letter1 = str("%")
if (letter1ID == 70):
	letter1 = str("^")
if (letter1ID == 71):
	letter1 = str("&")
if (letter1ID == 72):
	letter1 = str("*")
if (letter1ID == 73):
	letter1 = str("=")
if (letter1ID == 74):
	letter1 = str("-")
if (letter1ID == 75):
	letter1 = str("+")
if (letter1ID == 76):
	letter1 = str("_")
if (letter1ID == 77):
	letter1 = str("?")
if (letter1ID == 78):
	letter1 = str("<")
if (letter1ID == 79):
	letter1 = str(">")
if (letter1ID == 80):
	letter1 = str("~")
if (letter1ID == 81):
	letter1 = str("`")
if (letter1ID == 82):
	letter1 = str("\"")
if (letter1ID == 83):
	letter1 = str("/")
if (letter1ID == 84):
	letter1 = str(":")
if (letter1ID == 85):
	letter1 = str(";")
letter2ID = random.randint(0, 85)
if (letter2ID == 0 and letter2ID != letter1ID):
	letter2 = str("a")
if (letter2ID == 1 and letter2ID != letter1ID):
	letter2 = str("A")
if (letter2ID == 2 and letter2ID != letter1ID):
	letter2 = str("b")
if (letter1ID == 3 and letter2ID != letter1ID):
	letter1 = str("B")
if (letter1ID == 4 and letter2ID != letter1ID):
	letter1 = str("c")
if (letter1ID == 5 and letter2ID != letter1ID):
	letter1 = str("C")
if (letter1ID == 6 and letter2ID != letter1ID):
	letter1 = str("d")
if (letter1ID == 7 and letter2ID != letter1ID):
	letter1 = str("D")
if (letter1ID == 8 and letter2ID != letter1ID):
	letter1 = str("e")
if (letter1ID == 9 and letter2ID != letter1ID):
	letter1 = str("E")
if (letter1ID == 10 and letter2ID != letter1ID):
	letter1 = str("f")
if (letter1ID == 11 and letter2ID != letter1ID):
	letter1 = str("F")
if (letter1ID == 12 and letter2ID != letter1ID):
	letter1 = str("g")
if (letter1ID == 13 and letter2ID != letter1ID):
	letter1 = str("G")
if (letter1ID == 14 and letter2ID != letter1ID):
	letter1 = str("h")
if (letter1ID == 15 and letter2ID != letter1ID):
	letter1 = str("H")
if (letter1ID == 16 and letter2ID != letter1ID):
	letter1 = str("i")
if (letter1ID == 17 and letter2ID != letter1ID):
	letter1 = str("I")
if (letter1ID == 18 and letter2ID != letter1ID):
	letter1 = str("j")
if (letter1ID == 19 and letter2ID != letter1ID):
	letter1 = str("J")
if (letter1ID == 20 and letter2ID != letter1ID):
	letter1 = str("k")
if (letter1ID == 21 and letter2ID != letter1ID):
	letter1 = str("K")
if (letter1ID == 22 and letter2ID != letter1ID):
	letter1 = str("l")
if (letter1ID == 23 and letter2ID != letter1ID):
	letter1 = str("L")
if (letter1ID == 24 and letter2ID != letter1ID):
	letter1 = str("m")
if (letter1ID == 25 and letter2ID != letter1ID):
	letter1 = str("M")
if (letter1ID == 26 and letter2ID != letter1ID):
	letter1 = str("n")
if (letter1ID == 27 and letter2ID != letter1ID):
	letter1 = str("N")
if (letter1ID == 28 and letter2ID != letter1ID):
	letter1 = str("o")
if (letter1ID == 29 and letter2ID != letter1ID):
	letter1 = str("O")
if (letter1ID == 30 and letter2ID != letter1ID):
	letter1 = str("p")
if (letter1ID == 31 and letter2ID != letter1ID):
	letter1 = str("P")
if (letter1ID == 32 and letter2ID != letter1ID):
	letter1 = str("q")
if (letter1ID == 33 and letter2ID != letter1ID):
	letter1 = str("Q")
if (letter1ID == 34 and letter2ID != letter1ID):
	letter1 = str("r")
if (letter1ID == 35 and letter2ID != letter1ID):
	letter1 = str("R")
if (letter1ID == 36 and letter2ID != letter1ID):
	letter1 = str("s")
if (letter1ID == 37 and letter2ID != letter1ID):
	letter1 = str("S")
if (letter1ID == 38 and letter2ID != letter1ID):
	letter1 = str("T")
if (letter1ID == 39 and letter2ID != letter1ID):
	letter1 = str("t")
if (letter1ID == 40 and letter2ID != letter1ID):
	letter1 = str("u")
if (letter1ID == 41 and letter2ID != letter1ID):
	letter1 = str("U")
if (letter1ID == 42 and letter2ID != letter1ID):
	letter1 = str("v")
if (letter1ID == 43 and letter2ID != letter1ID):
	letter1 = str("V")
if (letter1ID == 44 and letter2ID != letter1ID):
	letter1 = str("w")
if (letter1ID == 45 and letter2ID != letter1ID):
	letter1 = str("W")
if (letter1ID == 46 and letter2ID != letter1ID):
	letter1 = str("x")
if (letter1ID == 47 and letter2ID != letter1ID):
	letter1 = str("X")
if (letter1ID == 48 and letter2ID != letter1ID):
	letter1 = str("y")
if (letter1ID == 49 and letter2ID != letter1ID):
	letter1 = str("Y")
if (letter1ID == 50 and letter2ID != letter1ID):
	letter1 = str("z")
if (letter1ID == 51 and letter2ID != letter1ID):
	letter1 = str("Z")
if (letter1ID == 52 and letter2ID != letter1ID):
	letter1 = str("0")
if (letter1ID == 53 and letter2ID != letter1ID):
	letter1 = str("1")
if (letter1ID == 54 and letter2ID != letter1ID):
	letter1 = str("2")
if (letter1ID == 55 and letter2ID != letter1ID):
	letter1 = str("3")
if (letter1ID == 56 and letter2ID != letter1ID):
	letter1 = str("4")
if (letter1ID == 57 and letter2ID != letter1ID):
	letter1 = str("5")
if (letter1ID == 58 and letter2ID != letter1ID):
	letter1 = str("6")
if (letter1ID == 59 and letter2ID != letter1ID):
	letter1 = str("7")
if (letter1ID == 60 and letter2ID != letter1ID):
	letter1 = str("8")
if (letter1ID == 61 and letter2ID != letter1ID):
	letter1 = str("9")
if (letter1ID == 62 and letter2ID != letter1ID):
	letter1 = str(",")
if (letter1ID == 63 and letter2ID != letter1ID):
	letter1 = str(".")
if (letter1ID == 64 and letter2ID != letter1ID):
	letter1 = str("!")
if (letter1ID == 65 and letter2ID != letter1ID):
	letter1 = str("@")
if (letter1ID == 66 and letter2ID != letter1ID):
	letter1 = str("#")
if (letter1ID == 67 and letter2ID != letter1ID):
	letter1 = str("$")
if (letter1ID == 68 and letter2ID != letter1ID):
	letter1 = str("!")
if (letter1ID == 69 and letter2ID != letter1ID):
	letter1 = str("%")
if (letter1ID == 70 and letter2ID != letter1ID):
	letter1 = str("^")
if (letter1ID == 71 and letter2ID != letter1ID):
	letter1 = str("&")
if (letter1ID == 72 and letter2ID != letter1ID):
	letter1 = str("*")
if (letter1ID == 73 and letter2ID != letter1ID):
	letter1 = str("=")
if (letter1ID == 74 and letter2ID != letter1ID):
	letter1 = str("-")
if (letter1ID == 75 and letter2ID != letter1ID):
	letter1 = str("+")
if (letter1ID == 76 and letter2ID != letter1ID):
	letter1 = str("_")
if (letter1ID == 77 and letter2ID != letter1ID):
	letter1 = str("?")
if (letter1ID == 78 and letter2ID != letter1ID):
	letter1 = str("<")
if (letter1ID == 79 and letter2ID != letter1ID):
	letter1 = str(">")
if (letter1ID == 80 and letter2ID != letter1ID):
	letter1 = str("~")
if (letter1ID == 81 and letter2ID != letter1ID):
	letter1 = str("`")
if (letter1ID == 82 and letter2ID != letter1ID):
	letter1 = str("\"")
if (letter1ID == 83 and letter2ID != letter1ID):
	letter1 = str("/")
if (letter1ID == 84 and letter2ID != letter1ID):
	letter1 = str(":")
if (letter1ID == 85 and letter2ID != letter1ID):
	letter1 = str(";")
letter3ID = random.randint(0, 512)
if (letter3ID == 0 and letter3ID != letter2ID):
	letter3 = str("a")
if (letter3ID == 1 and letter3ID != letter2ID):
	letter3 = str("A")
if (letter3ID == 2 and letter3ID != letter2ID):
	letter3 = str("b")
# Stopping here for now until I find a more efficient method. There HAS to be a better way to do this.

I am looking for ways to better optimize this, and continue to support various languages and alphabets. I am not looking for another language to do this in, unless it is absolutely necessary in the case that Python doesn't support that method.


@seanpm2001 seanpm2001 added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers question Further information is requested labels Dec 30, 2020
@seanpm2001 seanpm2001 self-assigned this Dec 30, 2020
@NihalKarne
Copy link

NihalKarne commented Dec 30, 2020

Hi, from what I understand you are looking for an efficient way to randomly select non repeated 55 character(alphabets/digits) that later can be used to display in a Snellen Chart. Have I understood it correctly?

@seanpm2001
Copy link
Owner Author

seanpm2001 commented Jan 4, 2021

Yes this is exactly it. Do you know of any ways? By the way, I am trying to find a method that works in multiple languages, so I can't rely on ASCII. I am trying to get it to also work for Cyrillic, Greek, Japanese, Georgian, and many other alphabets.

@NihalKarne
Copy link

NihalKarne commented Jan 4, 2021

I do have an idea for ASCII characters as of now. I will need to do more research to understand use other language characters. I can send a PR with a function which could return a list of 55 English letters randomly chosen. Would it help to get things started?

@seanpm2001
Copy link
Owner Author

Yes it would. Thank you for your help. I am not too good at pull requests at the moment, so I might need a little help confirming the request. I am still new to Git.

@NihalKarne
Copy link

For the other languages you will need to use unicode characters, I dont have lot of experience in it but as far as I understand each language have a defined range in the unicode series, all we need to do is select characters for a given language from that range and everything else would be similar. These two links might be of help Unicode Character Ranges
and Unicode & Character Encodings in Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants