Ad
Code
Diff
  • RandomBool=lambda:bool(ord(open('/dev/urandom','rb').read(1))&1)
    # This is also terribad, and the previous randint ones are better, but why not keep having fun
    • RandomBool=lambda:id(object())&1==0
    • RandomBool=lambda:bool(ord(open('/dev/urandom','rb').read(1))&1)
    • # This is also terribad, and the previous randint ones are better, but why not keep having fun
Fundamentals
Code
Diff
  • def main():
        play_again = True
        while play_again:
            word = input('Enter a string\n> ')
            print(f'>> The output is:  {word.upper()}')
            while (play_again := input('Would you like to play again? (y)es or (n)o :\n> ')):
                play_again = play_again.lower()
    
                if play_again == 'n':
                    print('goodbye')
                    play_again = False
                elif play_again != 'y':
                    print('Incorrect input!')
                    continue
                break
    
    
    if __name__ == '__main__':
        main()
    • def main():
    • word = input('Enter a string
    • > ')
    • print(f'>> The output is: {word.upper()}')
    • play_again = True
    • while play_again:
    • word = input('Enter a string
    • > ')
    • print(f'>> The output is: {word.upper()}')
    • while (play_again := input('Would you like to play again? (y)es or (n)o :\n> ')):
    • play_again = play_again.lower()
    • while True:
    • play_again = input('Would you like to play (y)es or (n)o :\n> ')
    • if play_again == 'y':
    • return main()
    • elif play_again == 'n':
    • print('goodbye')
    • if play_again == 'n':
    • print('goodbye')
    • play_again = False
    • elif play_again != 'y':
    • print('Incorrect input!')
    • continue
    • break
    • else:
    • print('Incorrect input!')
    • continue
    • if __name__ == '__main__':
    • main()
Code
Diff
  • RandomBool=lambda:id(object())%2==0
    • from random import getrandbits
    • RandomBool=lambda:bool(getrandbits(1))
    • RandomBool=lambda:id(object())%2==0
Code
Diff
  • import sys
    from pathlib import Path
    
    # looks like the original tries to print the contents of 
    # all files in the top 3 levels of the virtual environment
    # but has a problem where it's iterating over a string instead
    # of a recursive directory listing
    # namely it's like
    # >> os.listdir('.venv')
    # ['.bar', 'baz', '.foo']
    # then iterating over each one as if it's a dirname
    # so it tries opening .venv/., then .venv/b, then .venv/a then .venv/r
    # it's also printing a listdir of the nested directories instead of saving
    # the listdir, which might make it work if subsequently iterated
    # I'd imagine it's trying to print all text files in the virtual environment
    # this would do what the original looks like it's trying to do,
    # with a bonus of actually working if the venv isn't in ${pwd}/.venv
    # and if you're in a venv
    def walk_dont_run():
        if sys.prefix != sys.base_prefix:
            start = Path(sys.prefix)
            if start:
                for path in start.glob('**/*'):
                    try:
                        print(path.read_text())
                    except: pass
    
    • import os
    • import subprocess
    • print((ve := os.listdir(".venv")))
    • for x in ve:
    • try:
    • print(x, os.listdir(f".venv/{x}"))
    • for y in x:
    • try:
    • print(y, os.listdir(f".venv/{x}/{y}"))
    • for z in y:
    • try:
    • with open(f".venv/{x}/{y}/{z}","r") as file: print(file.open())
    • except:
    • print("...goes on...")
    • except:
    • import sys
    • from pathlib import Path
    • # looks like the original tries to print the contents of
    • # all files in the top 3 levels of the virtual environment
    • # but has a problem where it's iterating over a string instead
    • # of a recursive directory listing
    • # namely it's like
    • # >> os.listdir('.venv')
    • # ['.bar', 'baz', '.foo']
    • # then iterating over each one as if it's a dirname
    • # so it tries opening .venv/., then .venv/b, then .venv/a then .venv/r
    • # it's also printing a listdir of the nested directories instead of saving
    • # the listdir, which might make it work if subsequently iterated
    • # I'd imagine it's trying to print all text files in the virtual environment
    • # this would do what the original looks like it's trying to do,
    • # with a bonus of actually working if the venv isn't in ${pwd}/.venv
    • # and if you're in a venv
    • def walk_dont_run():
    • if sys.prefix != sys.base_prefix:
    • start = Path(sys.prefix)
    • if start:
    • for path in start.glob('**/*'):
    • try:
    • with open(rf".venv/{x}") as f:
    • print(f.read())
    • except:
    • print()
    • except:
    • with open(rf".venv/{x}") as f:
    • print(f.read())
    • print(path.read_text())
    • except: pass
Code
Diff
  • from random import choice
    class Random_Bool:
        @staticmethod
        def r():
            return choice((True, False))
    
    • from random import getrandbits
    • class Random_Bool(object):
    • def __repr__(self):
    • return repr(self.r())
    • def __init__(self):
    • self.r = lambda: bool(getrandbits(1))
    • random_boolean = Random_Bool()
    • from random import choice
    • class Random_Bool:
    • @staticmethod
    • def r():
    • return choice((True, False))
Code
Diff
  • ring = ''.join(''.join([chr(i+7)]*j) for i,j in zip([90,110,96,97],[5,3,2,4]))
    • ring = ''.join(chr(i+7) for i in [90, 90, 90, 90, 90, 110, 110, 110, 96, 96, 97, 97, 97, 97])
    • ring = ''.join(''.join([chr(i+7)]*j) for i,j in zip([90,110,96,97],[5,3,2,4]))