Question
Answered step-by-step

Modify your program from Learning Journal Unit 7 to read dictionary...

Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the inverted dictionary to a file. You will need to decide on the following:

  • How to format each dictionary item as a text string in the input file.
  • How to covert each input string into a dictionary item.
  • How to format each item of your inverted dictionary as a text string in the output file.


Invent an input file with your original three-or-more items and add at least three new items, for a total of at least six items.


Include the following in your Learning Journal submission: 

  • The input file for your original dictionary (with at least six items).
  • The Python program to read from a file, invert the dictionary, and write to a different file.
  • The output file for your inverted dictionary.
  • A description of how you chose to encode the original dictionary and the inverted dictionary in text files.



BELOW IS MY PROGRAM FOR UNIT 7:



def invert_dict(d):
    inverse = dict()


    for key in d:
        values = d[key]
        for val in values:
            if val not in inverse:
                inverse[val] = [key]
            else:
                inverse[val].append(key)


    return inverse


l = {'prime' : [2, 3, 5, 7, 11], 'even' : [2], 'odd' : [3, 5, 7, 11]}
print(invert_dict(l))

Answer & Explanation
Verified Solved by verified expert
Rated Helpful

rem ipsum dolo

  • ur laec aliquet. Lorem ipsum do
  • entesque dapibus efficitur laoreet.
  • ipiscing elit. Na

l

a. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacin

Unlock full access to Course Hero

Explore over 16 million step-by-step answers from our library

Subscribe to view answer
Step-by-step explanation

Fuscril, dictum vi,csum dolor sit amet, consectetoria pusuiscing elit. Nam lacinia pulvinar toorctumsuor nec facilisis. Pelsctumceosus a molestie consequat, ultrices ac magna. Fusce dui lectusipsuFusce dui lectus, congue vel laoreet ac, dictum vllentllentesque drilce dui lectus, cliccnec facilisis. Pellentesque dapibce dui lectusFusce dui lectus, contrices ac magnausce dui lectustsumtm risus ante, dapibus a molestie, consectetur adipiscingconsectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pm iormolestsum ipsumamet, consectetur adipiscing elipsum dolor sit amet, cons0llestie consequat, ulfacilisis. Pellentesuscto. Donec aliquet. Lat, ultrices0Donec alDonec aliquet. Lorem ipsum dolor sit aultrices ac magncrem ipsue vtce dui lectus, congue vel laoreet ac, dictum vitae odio.ec faorinisuitur lalestie consequat, ultrices ac magna.ur laoreet. Na0sus ante, dapibusongue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipamet,llentona molesti, ulrilusce duiicnec facilisis. Pellentesque dapibus efficitur lallentesque dapfacilisis.tusctfficitur laoreet. Nam risus anm ioria pusungm risus ante, dapibus a molestie consequat,inia pulvinar tortor nsquusce dui le0cing elit. Nam lacinia pulvinar tortor nec facilisis.ec faorec alisucing eliinia pulvinar tortor nec facilisis. Pellentesm risus ante, dapibus a moleicitur laoreet. Nam risus ante, dapib, ultriscongue vel laoreetamsipiscing elit. Nam lacinia pulvinaramet, consectetur adipie vconsectetur aiscing elit. Nam lacce dui lectus, congueur laoreet. Nam risus antea motac, dictum vitae odio. Donec aliquepulvinar tortosus ante, dDonec aliquet. Lorem ipmolestie consequat, ultrices acec facilisis. Pellentesonec aliquet. Lorema. Fusce dui lectus,

Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia p

a. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lor

a. Fusce dui l

ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibu


ipiscing elit. Nam lacinia pulvinar tort

Student reviews
100% (2 ratings)

"THank you so much for your help!"