Python Test:: 1) A ( Bangalore', Pune', Delhi', Mumbai')
Python Test:: 1) A ( Bangalore', Pune', Delhi', Mumbai')
How would you search for ‘Bangalore’ in these? Which structure is more optimal for searching
and why?
1) A = [‘Bangalore’, ‘Pune’, ‘Delhi’, ‘Mumbai’]
# initializing list
A= ['Bangalore', 'Pune', 'Delhi', 'Mumbai']
# initializing substring
substr = 'Bangalore'
# printing result
print ("String being searched for : " + str(res))
# initializing list
A= set(['Bangalore', 'Pune', 'Delhi', 'Mumbai'])
# initializing substring
substr = 'Bangalore'
# printing result
print ("String being searched for : " + str(res))
Def fun(x):
x[0] = 5
return x
3. While importing a file “temp.csv” using pandas, you encounter the following error:
What is the cause of this and how would you fix it?
Here the error is related to ASCII code, and if a character string is not there in ASCII code page,
above error will be shown. Possibly the code is not running in Python 3.x version. For fixing
either we need to run the code in Python 3.x version, or use a unicode string at the top of the
code. Here we can use encoding ‘utf-8’.
4. Given a list of strings as shown below, how would you convert them to datetime format?
These strings can be converted to datetime format, by importing a packaged library named
datetime where we need to define the syntax of date. See below example:
6. From the SQL part of the test, pick out any two questions and solve them in python using
pandas.