#๐ Why is THIS possible?
28 messages ยท Page 1 of 1 (latest)
@twilit hamlet
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.
For strings this would be using the ordinal number
what's that?
!py
ord("a")
Why Avoid System Python for Development on Unix-like Systems:
- Critical Operating System Dependencies: Altering the system Python installation may harm internal operating system dependencies.
- Stability and Security Concerns: System interpreters lag behind current releases, lacking the latest features and security patches.
- Limited Package Control: External package management restricts control over versions, leading to compatibility issues with outdated packages.
Recommended Approach:
- Install Independent Interpreter: Install Python from source or utilize a virtual environment for flexibility and control.
- Utilize Pyenv or Similar Tools: Manage multiple Python versions and create isolated development environments for smoother workflows.
!e
print(ord("a"))
:white_check_mark: Your 3.12 eval job has completed with return code 0.
97
not ASCII exactly, as this works for any unicode character
but the idea is the same
!e
print("What?")
:white_check_mark: Your 3.12 eval job has completed with return code 0.
What?
!e
print([i for i in range(200000000)])
:warning: Your 3.12 eval job timed out or ran out of memory.
[No output]
lol
it's also relevant to know, that < is used for sorting things.
so if you got a list of names, you can sort it, and internally it's using < to compare each item (by default at least)
!e
names = ['sani', 'retopear', 'alice', 'zorro']
names.sort()
print(names)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
['alice', 'retopear', 'sani', 'zorro']
!e though because it's using the ordinal value of the letters, it might mess up the sorting, if you have mixed cases of your letters:
names = ['sani', 'retopear', 'alice', 'Zorro']
names.sort()
print(names)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
['Zorro', 'alice', 'retopear', 'sani']
as all capital letters have a lower ordinal value as their lowercase counterparts
you can fix that by using a key:
names.sort(key=str.casefold)
๐
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.