[ Write a program to print negative Numbers in given range ]
Write a program to print negative Numbers in given range
start, end = -4, 19
for num in range(start, end + 1):
if num < 0:
print(num, end = " ")
Write a program to remove empty List from List using list comprehension
test_list = [5, 6, [], 3, [], [], 9]
print("The original list is : " + str(test_list))
res = [ele for ele in test_list if ele != []]
print ("List after empty list removal : " + str(res))
Write a program to remove empty tuples from a list of tuples
def Remove(tuples):
tuples = filter(None, tuples)
return tuples
#Driver Code
tuples = [(), ('ram','15','8'), (), ('laxman', 'sita'),
('krishna', 'akbar', '45'), ('',''),()]
print Remove(tuples)
Write a program to break a list into chunks of size N
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
n = 4
x = [l[i:i + n] for i in range(0, len(l), n)]
print(x)
Write a program to find the frequency of words present in a string
test_str = 'times of india times new india express'
print("The original string is : " + str(test_str))
res = {key: test_str.count(key) for key in test_str.split()}
print("The words frequency : " + str(res))
Write a program to accept a string if it contains all vowels
def check(string):
if len(set(string).intersection("AEIOUaeiou"))>=5:
return ('accepted')
else:
return ("not accepted")
if __name__=="__main__":
string="helloworld"
print(check(string))
Write a program to rotate string left and right by d length
def rotate(input,d):
Lfirst = input[0 : d]
Lsecond = input[d :]
Rfirst = input[0 : len(input)-d]
Rsecond = input[len(input)-d : ]
print ("Left Rotation : ", (Lsecond + Lfirst) )
print ("Right Rotation : ", (Rsecond + Rfirst))
if __name__ == "__main__":
input = 'helloworld'
d=2
rotate(input,d)