assume you have a dictionary mydict where all values are eit
assume you have a dictionary my_dict where all values are either strings or integers. Write a piece of Python code that doubes all integer values and makes all string values uppercase
Solution
Following is the program that reads data i.e string from the file and converts it into uppercase
import os
def sample(my_dict):
//data to be read and writen or appended to the file.//
with open(my_dict.., \"r+b\") as file:
//the contents of the file are being read.
content = file.read()
file.seek(0)
//Contents of the file are converted to uppercase//
file.write(content.upper())
//Filename is to be passed in my_dict
The above statement can also be executed at the command line. Following is the command that is used to do so:
ls -1 | parallel python upper.py
import os, sys
//Open the file and read the contents of the file
with open(sys.argv[1], \"r+b\") as file:
content = file.read()
file.seek(0)
file.write(content.upper())
//If the contents of the file are integers and the numbers are to be doubled, the following code is to be implemented:
//Assume that there is a list with integers
k=[2,4,6]
def double(list):
for j, k in enumerate(lst):
k *= 2
print(\"k = %s\" % k)
print(\"list[%d] = %s\" % (k, list[j]))
Output:
//For strings
DISPLAY ALPHABETS IN UPPER CASE
//For integers
input:
n = [2, 4, 6]
print (double(n))
Output:
[4, 8, 12]
