Sandisk Interview Question and Answers

1) Write a program for the below input and output
IN = "I_live_in_Bangalore"
OP1 = "___IliveinBangalore"
OP2 = "_Iieiaaoe_lvnBnglr"
    IN = "I_live_in_Bangalore"
    other = []
    ch = []
    ov = []
    con = []
    for c in IN:
        if c == "_":
            other.append(c)
        else:
            ch.append(c)
            if c.lower() in "aeioou":
                ov.append(c)
            else:
                con.append(c)
    op1 = "".join(other) + "".join(ch)
    print(op1)
    >>> ___IliveinBangalore
    ov = "".join(ov)
    con = "".join(con)
    l = [ov, con]
    op2 = ""
    for i in range(len(l)):
        op2 += other[i] + l[i]
    print(op2)
    >>> _Iieiaaoe_lvnBnglr

2) What is constructor overloading?

3) What is the difference between list and tuple?

4) Where tuple is used?

5) How python code is compiled?

6) What are compile time errors?

7) What are run time errors?

8) Write a program to get a single list from the given list.
    l = [[1,2,3,4], "man", "woman"]
    rs = []
    for i in l:
        if type(i) == str:
            rs.append(i)
        else:
            rs.extend(i)
    print(rs)
    >>> [1, 2, 3, 4, 'man', 'woman']

   
9) Create a program to read a file and find how many times "Python" word is repeated.
    c = 0
    with open("resume.txt", "r") as fh:
        for line in fh:
            l = line.split()
            c += l.count("Python")
    print(c)

10) write a program to read a file and count the words and put it in a dictionary.
    import re
    words = []
    d = {}
    with open("resume.txt", "r") as fh:
        for line in fh:
            l = re.findall(r"[a-zA-z]{2,}", line)
            words.extend(l)
    uw = list(set(words))  
    for w in uw:
        d[w]= words.count(w)
    print(d)

11) Create a class to add two numbers.
    class sum():
        def __init__(self, n1, n2):
            self.n1 = n1
            self.n2 = n2
        def add(self):
            return self.n1 + self.n2
    s = sum(4,5)
    print(s.add())
>>> 9

Comments