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

using python Write a function named symmetry that takes a string, text, as a par

ID: 3764208 • Letter: U

Question

using python

Write a function named symmetry that takes a string, text, as a parameter and returns a dictionary d. Every letter that is both the first and last letter of some word in text should be a key in d. For example, if text contains the word 'shucks', 's' should be a key in d. The value of 's' in d is the number of words that both begin and end with 's'. The parameter text contains only upper and lower case characters and white space.

The following is an example of correct output:

t = '''The sun did not shine it was too wet to play so we sat in the house all that cold cold wet day

I sat there with Sally we sat there we two and I said how I wish we had something to do'''

print(symmetry(t)) {'d': 1, 'i': 3, 't': 1}

Explanation / Answer

The for loop traverses the string. Each time through the loop, if the character c is not in the dictionary, we create a new item with key c and the initial value 1