Categories:Viewed: 6 - Published at: a few seconds ago

Write a python program to implement Queue

from collections import deque

class Queue():
    Thread-safe, memory-efficient, maximally-sized queue supporting queueing and
    dequeueing in worst-case O(1) time.

    def __init__(self, max_size = 10):
        Initialize this queue to the empty queue.

        max_size : int
            Maximum number of items contained in this queue. Defaults to 10.

        self._queue = deque(maxlen=max_size)

    def enqueue(self, item):
        Queues the passed item (i.e., pushes this item onto the tail of this

        If this queue is already full, the item at the head of this queue
        is silently removed from this queue *before* the passed item is


    def dequeue(self):
        Dequeues (i.e., removes) the item at the head of this queue *and*
        returns this item.

            If this queue is empty.

        return self._queue.pop()

Write a python function to get the most common word in text

def most_common(text):
    c = Counter(text)
    return c.most_common(1)

Write a python function to do bitwise multiplication on a given bin number by given shifts

def bit_mul(n, shift):
    return n << shift

Write a python function for bitwise division with given number of shifts

def bit_div(n, shift):
    return n >> shift

Write a python function to get dot product between two lists of numbers

def dot_product(a, b):
    return sum(e[0] * e[1] for e in zip(a, b))

Write a python function to strip punctuations from a given string

def strip_punctuations(s):
    return s.translate(str.maketrans('', '', string.punctuation))

Write a python function that returns biggest character in a string

from functools import reduce

def biggest_char(string):
    if not isinstance(string, str):
        raise TypeError
    return reduce(lambda x, y: x if ord(x) > ord(y) else y, string)

Write a python function to Count the Number of Digits in a Number

def count_digits():
    n = int(input("Enter number:"))
    count = 0
    while n > 0:
        count = count + 1
        n = n // 10
    return count

Write a python function to count number of vowels in a string

def count_vowels(text):
    v = set('aeiou')
    for i in v:
        print(f'\n {i} occurs {text.count(i)} times')