we begin by creating an empty dictionary then we iterate over each file listed on the command line and each line within each file we must account for the fact that each line may refer to any number of web siteswhich is why we keep calling str find(until it fails if we find the string "(our starting index positionby the length of "succeeding character until we reach one that isn' valid for web site' name if we find site (and as simply sanity checkonly if it contains period)we add it to the dictionary we cannot use the syntax sites[siteadd(filenamebecause this will raise keyerror exception the first time new site is encountered--after allwe can' add to set that is the value of an item that does not yet exist in the dictionary so we must use different approach the dict setdefault(method returns an object reference to the item in the dictionary that has the given key (the first argumentif there is no such itemthe method creates new item with the key and sets its value either to noneor to the given default value (the second argumentin this case we pass default value of set()that isan empty set so the call to dict setdefault(always returns an object reference to valueeither one that existed before or new one (of courseif the given key is not hashable typeerror exception will be raised in this examplethe returned object reference always refers to set (an empty set the first time any particular keythat issiteis encountered)and we then add the filename that refers to the site to the site' set of filenames by using set we ensure that even if file refers to site repeatedlywe record the filename only once for the site to make the dict setdefault(method' functionality clearhere are two equivalent code snippetssites setdefault(siteset()add(fnameif site not in sitessites[siteset(sites[siteadd(fnamefor the sake of completenesshere is the rest of the programfor site in sorted(sites)print("{ is referred to in:format(site)for filename in sorted(sites[site]key=str lower)print({ }format(filename)each web site is printed with the files that refer to it printed indented underneath the sorted(call in the outer for in loop sorts all the dictionary' keys--whenever dictionary is used in context that requires an iterable it is the keys that are used if we want the iterable to be the (keyvalueitems or the valueswe can use dict items(or dict values(the inner for in loop iterates over the sorted filenames from the current site' set of filenames sorted(