Skip to content

Instantly share code, notes, and snippets.

@the-rahulpatel
Created April 17, 2021 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the-rahulpatel/c7c010ef7a16dd4f2b09cbe6d582ec06 to your computer and use it in GitHub Desktop.
Save the-rahulpatel/c7c010ef7a16dd4f2b09cbe6d582ec06 to your computer and use it in GitHub Desktop.
Answers of doughsay/lc-practice.py
def identity(nums):
return [i for i in nums]
# without list comprehension
# return [*nums]
def doubled(nums):
return [i*2 for i in nums]
def squred(nums):
return [i**2 for i in nums]
def evens(nums):
return [i for i in nums if i % 2 == 0]
def odds(nums):
return [i for i in nums if i % 2 != 0]
# or
# return [i for i in nums if i not in evens(nums)]
def positives(nums):
return [i for i in nums if i > 0]
def selective_stringify_nums(nums):
# 0 == False: Output: True, so i%5==0 is false
# 5 % 5 == 0: bool(5 % 5) <=> False, so not 5 % 5: True
# if x means if x is true => so if not i % 5
return [str(i) for i in nums if not i % 5]
def encrypt_lol(sentence):
# answer provided by the creator demonstrates that 'y' is unchnaged.
return ''.join(chr(ord(i) + 1) if ord(i) in range(ord('a'),ord('y')) else i for i in sentence)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment