Skip to content

Instantly share code, notes, and snippets.

@sid86-dev
Created October 3, 2021 06:31
Show Gist options
  • Save sid86-dev/ef74b78f49b754a6a724fdc7db640924 to your computer and use it in GitHub Desktop.
Save sid86-dev/ef74b78f49b754a6a724fdc7db640924 to your computer and use it in GitHub Desktop.
'''1.
If you are a list of integers (that are non negative) write a program to return an integer list of the
rightmost digits.
right([1,22,94]) ->[1,2,4]
right([10,0]) ->[0,0]
'''
def right(lst):
new_lst = []
for item in lst:
lst = [int(a) for a in str(item)]
new_lst.append(lst[(len(lst))-1])
return new_lst
print(right([1,22,94]))
print(right([10,0]))
'''2.
If you have a list of strings, write a program to return a list where a * is added at the end of each string.
addstar["a","hello","hai","*"]) --->["a*","hello*","hai*","**"]
'''
def addstar(lst):
return [i+'*' for i in lst]
print(addstar(["a","hello","hai","*"]))
'''3.
If you have a list of strings, write a program to display a list where each input string is converted to
lower case.
lower(["Choc"]) --------> choc
'''
def lower(lst):
return [i.lower() for i in lst]
print(lower(["Choc"]))
'''
4.Consider a list of strings, return a list where each string is replaced by 3 copies of the concatenated string example:
Input ->(["a","bb"]) ------> Output ->(["aaa","bbbbbb"])
'''
def copy(lst):
return [i+i+i for i in lst]
print(copy(["a","bb"]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment