Question

In: Computer Science

my_list = {} Dictionary holding all the lists. s_files = [] # Files with size UNDER...

my_list = {} Dictionary holding all the lists. s_files = [] # Files with size UNDER 50 KB. m_files = [] # Files with size AT LEAST 50 KB and UNDER 5 MB . l_files = [] # Files with size AT LEAST 5 MB, no upper limit. directories = [] # Directories, regardless of size. Write a program using python that loops over each file in a specified directory and checks the size of each file.Create 2-tuple with the filename and size, should append the 2-tuple to a list, and then store all the lists in a dictionary according to the size

Solutions

Expert Solution

import os

my_list = {} #Dictionary holding all the lists.
s_files = [] # Files with size UNDER 50 KB.
m_files = [] # Files with size AT LEAST 50 KB and UNDER 5 MB
l_files = [] # Files with size AT LEAST 5 MB, no upper limit.
directories = [] # Directories, regardless of size.
# enter the path of your directory here
directory = r'E:\test'
Unit = ["Byte","KB","MB","GB","TB"]
for filename in os.listdir(directory):
    c = 0
    # this will get the file size in bytes
    b = os.path.getsize(os.path.join(directory, filename))
    # this will convert bytes to MB.... GB... etc
    while b > 1024:
        b = b/1024
        c+=1
    size = "{:.1f}".format(b)+ " " + Unit[c]
    tup = (filename,size)
    # to check print output of each tuple
    print(tup)
    directories.append(tup)
    if Unit[c]=="Byte" or Unit[c]=="KB" and b<50 :
        s_files.append(tup)
    elif (Unit[c]=="KB" and b>=50) or (Unit[c]=="MB" and b<5) :
        m_files.append(tup)
    else:
        l_files.append(tup)
my_list["under 50 KB"]= s_files
my_list["between 50 KB and 5 MB"]= m_files
my_list["above 5 MB"]= l_files

This code will work for the above program

Hope this helpful

Please please please upvote as it will helps me alot

please dont downvote


Related Solutions

(a) Holding all other values constant, increasing the sample size increases the power of a hypothesis...
(a) Holding all other values constant, increasing the sample size increases the power of a hypothesis test. (True/False) (b) If a 95% confidence interval (CI) for μ is (52, 58), then 95% of the population values are between 52 and 58. (True/False) (c) If the population distribution (X dist.) is normal, then the sampling distribution of X̅ is normal for a random sample of any size. (True/False) (d) A 95% confidence interval for μ was computed to be (30, 35)....
In Python This assignment involves the use of text files, lists, and exception handling and is...
In Python This assignment involves the use of text files, lists, and exception handling and is a continuation of the baby file assignment. You should now have two files … one called boynames2014.txt and one called girlnames2014.txt - each containing the top 100 names for each gender from 2014. Write a program which allows the user to search your files for a boy or girl name and display where that name ranked in 2014. For example … >>>   Enter gender...
This assignment involves the use of text files, lists, and exception handling and is a continuation...
This assignment involves the use of text files, lists, and exception handling and is a continuation of the baby file assignment. You should now have two files … one called boynames2014.txt and one called girlnames2014.txt - each containing the top 100 names for each gender from 2014. Write a program which allows the user to search your files for a boy or girl name and display where that name ranked in 2014. For example … >>> Enter gender (boy/girl): boy...
Write the function letter_frequencies(text) that returns a dictionary containing all of the letter frequencies of all...
Write the function letter_frequencies(text) that returns a dictionary containing all of the letter frequencies of all letters occurring in the parameter text. For example: if __name__ == '__main__': d = letter_frequencies('hello, world') print(d) # show the contents of this dictionary will produce the following output: {'a': 0.0, 'b': 0.0, 'c': 0.0, 'd': 0.1, 'e': 0.1, 'f': 0.0, 'g': 0.0, 'h': 0.1, 'i': 0.0, 'j': 0.0, 'k': 0.0, 'l': 0.3, 'm': 0.0, 'n': 0.0, 'o': 0.2, 'p': 0.0, 'q': 0.0,'r': 0.1,...
PYTHON Computer Science Objectives Work with lists Work with functions Work with files Assignment Write each...
PYTHON Computer Science Objectives Work with lists Work with functions Work with files Assignment Write each of the following functions. The function header must be implemented exactly as specified. Write a main function that tests each of your functions. Specifics In the main function ask for a filename and fill a list with the values from the file. Each file should have one numeric value per line. This has been done numerous times in class. You can create the data...
Put a metric ρ on all the words in a dictionary by defining the distance between...
Put a metric ρ on all the words in a dictionary by defining the distance between two distinct words to be 2^−n if the words agree for the first n letters and are different at the (n+1)st letter. A space is distinct from a letter. E.g., ρ(car,cart)=2^−3 and ρ(car,call)=2^−2. a) Verify that this is a metric. b) Suppose that words w1, w2 and w3 are listed in alphabetical order. Find a formula for ρ(w1,w3) in terms of ρ(w1,w2) and ρ(w2,w3).
Their price lists are shown in the table Ordering cost is $55, and annual holding cost per unit is $4
M.P. VanOyen Manufacturing has gone out on bid for a regulator component. Expected demand is 725 units per month. The item can be purchased from either Allen Manufacturing or Baker Manufacturing. Their price lists are shown in the table Ordering cost is $55, and annual holding cost per unit is $4    Allen Mfg.Baker Mfg.QuantityUnit PriceQuantityUnit Price1-499$16.00  1-399$16.10  500-99915.50400-79915.601000+15.00800+15.10a) What is the economic order quantity if price is not a consideration? b) Which supplier, based on all options with regard to discounts,...
Consider a file system that uses inodes to represent files. Diskblocks are 8 kb in size,...
Consider a file system that uses inodes to represent files. Diskblocks are 8 kb in size, and a pointer to a disk block requires 4bytes. this file system has 12 direct disk blocks, as well assingle, double, and triple in direct disk blocks. What is themaximum size of a file that can be stored in this file system?Explain a little bit^^ Thank you
A tablet PC contains 3217 music files. The distribution of file size is highly skewed with...
A tablet PC contains 3217 music files. The distribution of file size is highly skewed with many small file sizes. The mean file size on the tablet is 2.35 MB with a standard deviation of 3.25 MB. a What is the probability that the average size of 30 randomly selected music files taken from the tablet is more than 2.75 MB? b What is the probability that the average size of 50 randomly selected music files taken from the tablet...
A tablet PC contains 3217 music files. The distribution of file size is highly skewed with...
A tablet PC contains 3217 music files. The distribution of file size is highly skewed with many small files. Suppose the true mean file size of music and video files on the tab, LaTeX: \mu\:=\:2.30μ = 2.30 MB, and also assume that the standard deviation for this population (LaTeX: \sigmaσ )is 3.25 megabytes (MB). If you select a random sample of 50 files. a. What is the probability that the mean file size of your sample (50 files as described...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT