0% found this document useful (0 votes)
42 views

Python Intern CT

The document contains 9 Python programming assignments: 1) Read a file line by line and store in a list. 2) Calculate days between dates. 3) Convert Python dictionary to JSON with indent 4. 4) Sort list of dictionaries by key using Lambda. 5) Count words in a text file ignoring comma separated words. 6) Convert array to bytes representation. 7) Read log files line by line and write to new file with date time suffix. 8) Generate random logs and write to new files once size reaches 2MB. 9) Ping IPs and check if software installed like Java, kubectl, AWS.

Uploaded by

zack
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Python Intern CT

The document contains 9 Python programming assignments: 1) Read a file line by line and store in a list. 2) Calculate days between dates. 3) Convert Python dictionary to JSON with indent 4. 4) Sort list of dictionaries by key using Lambda. 5) Count words in a text file ignoring comma separated words. 6) Convert array to bytes representation. 7) Read log files line by line and write to new file with date time suffix. 8) Generate random logs and write to new files once size reaches 2MB. 9) Ping IPs and check if software installed like Java, kubectl, AWS.

Uploaded by

zack
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment : Python

1: Write a Python program to read a file line by line and store it into a list.

2: Write a Python program to calculate the number of days between two dates.
Sample dates : (20200702), (20200711)

3: Write a Python program to convert the Python dictionary object (sort by key) to
JSON data. Print the object members with indent level 4.

4: Write a Python program to sort a list of dictionaries using Lambda.


Original list of dictionaries :
[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Mi Max', 'model': '2',
'color': 'Gold'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}]
Sorting the List of dictionaries :
[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7,
'color': 'Blue'}, {'make': 'Mi Max', 'model': '2', 'color': 'Gold'}]

5: Write a Python program that takes a text file as input and returns the number of
words of a given text file.
Note: Some words can be separated by a comma with no space.

6: Write a Python program to convert an array to an array of machine values and


return the bytes representation.
Expected Output:
Original array:
A1: array('i', [1, 2, 3, 4, 5, 6])
Array of bytes: b'010000000200000003000000040000000500000006000000'

7: Write a script which can read the files line by line with .log ext and print it into a
file , while printing the data from the suffix with present date and time of the system.
(example of file path are /home/Desktop/demo/test.log,
/home/Desktop/demo/test-1.log, /home/Desktop/demo/test2.log, .....)
(sample data inside the .log files
03-17 16:13:38.811 1702 2395 D WindowManager:
printFreezingDisplayLogsopening app wtoken = AppWindowToken{9f4ef63
token=Token{a64f992 ActivityRecord{de9231d u0
com.tencent.qt.qtl/.activity.info.NewsDetailXmlActivity t761}}}, allDrawn= false,
startingDisplayed = false, startingMoved = false, isRelaunching = false
03-17 16:13:38.819 1702 8671 D PowerManagerService: acquire lock=233570404,
flags=0x1, tag="View Lock", name=com.android.systemui, ws=null, uid=10037,
pid=2227
03-17 16:13:38.820 1702 8671 D PowerManagerService:
ready=true,policy=3,wakefulness=1,wksummary=0x23,uasummary=0x1,bootcomplete
d=true,boostinprogress=false,waitmodeenable=false,mode=false,manual=38,auto=-1,a
dj=0.0userId=0
03-17 16:13:38.839 1702 2113 V WindowManager: Skipping
AppWindowToken{df0798e token=Token{78af589 ActivityRecord{3b04890 u0
com.tencent.qt.qtl/com.tencent.video.player.activity.PlayerActivity t761}}} -- going to
hide
03-17 16:13:38.859 2227 2227 D TextView: visible is system.time.showampm
03-17 16:13:38.861 2227 2227 D TextView: mVisiblity.getValue is false
03-17 16:13:38.869 2227 2227 D TextView: visible is system.charge.show
03-17 16:13:38.887 2227 2227 D TextView: visible is system.ownerinfo.show
)
8: Program to Generate random logs and write in a file , once the file size reaches 2Mb
open new file and continue writing

9: Script to ping and check whether any given IPs are active, also whether given set of
software are installed in the existing system ( like java, kubectl, aws etc)

You might also like