-
Notifications
You must be signed in to change notification settings - Fork 0
Python 1
-
Write a program which will open a text file and print the last 5 lines
-
Write a program which will print the length of the longest line in a text file
-
Suppose you have a text file each line of which is a single word; for example:
hello ant cat elephant
Write a Python program which will display the lines in sorted order. The output in the above case should be:
ant
cat
elephant
hello
-
Write a Python program which will print all lines of a text file which contains the following pattern:
An upper case A followed by any number of digits ending with an upper case B
For example, if the file contains lines like these:
helloA01123Bpqr
A9812BCqtmn
those lines should be printed on to the screen. Use regular expressions for solving this.
-
Write a Python program which will find out the largest file in the current directory. (hint: use "listdir" function from "os" module to find out names of all files; use the "stat" function from "os" module to get size of each file)
-
Read about the "binary search" algorithm on the net. Write a Python function to implement the binary search algorithm. The function should look like this:
def binsearch(a, n): # Check whether number "n" is present in a sorted list "a" # If present, return index of the location where the number is present # Otherwise, return -1