Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2Write a function keepTypeslast where Ist is a list of strings. The strings repr

ID: 3597884 • Letter: 2

Question

2Write a function keepTypeslast where Ist is a list of strings. The strings represent file . names - some with and some without extensions. This function keeps a list of unique file extensions. Filenames without extensions are ignored. Output is shown below. You must use format for the first entry in the list to get full credit. The file extensions are in sorted order. Extensions, where they exist, will always be at least one character in length. >>> keepTypesCC'hello.txt', 'yes.txt', 'no.docx ', 'no. doc',' three.jpg", 'no.png'I) ('5 file types ', 'doc ', 'docx', 'jpg', 'png', txt'] no three no' >>> keepTypesCC'hello.txt ", 'yes ', 'no', '',' ', 'I) ('1 file types ', 'txt] >>> keepTypesCC'hello.txt ','yes.txt",'no.docx","no.doc', 'three.png','no.png'I) doc png txt'] ('4 file types', '', 'docx', '', ' >>> keepTypesCI) ' file types'] >>> keepTypesCC'x', 'y', 'z'I) ('o file types']

Explanation / Answer

def keepTypes(list):
    list1 = ['0 file types']
    count = 0
    for i in range(len(list)):
        if '.' in list[i]:
          if list[i].split('.')[1] not in list1:
              list1.append(list[i].split('.')[1])
              count = count + 1
              list1[0] = str(count) + " file types"

    for i in range(1,len(list1)):
        for j in range(i,len(list1)):
            if list1[i] > list1[j]:
               temp = list1[i]
               list1[i] = list1[j]
               list1[j] = temp
    return list1

print(keepTypes(['hello.txt','yes.doc','no.docx','no.doc','three.jpg','no.png']))
print(keepTypes(['hello.txt','yes','no','no','three','no']))
print(keepTypes(['hello.txt','yes.doc','no.docx','no.doc','three.png','no.png']))
print(keepTypes([]))
print(keepTypes(['x','y','z']))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote