Created
April 17, 2021 06:11
-
-
Save the-rahulpatel/c7c010ef7a16dd4f2b09cbe6d582ec06 to your computer and use it in GitHub Desktop.
Answers of doughsay/lc-practice.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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