Computer Science, asked by unatha4, 2 months ago

Write a Python program to create a dictionary from a string ‘w3resource’ such that each individual character mates a key and its index value for fist occurrence males the corresponding value in dictionary.
Expected output : {'3': 1, 's': 4, 'r': 2, 'u': 6, 'w': 0, 'c': 8, 'e': 3, 'o': 5}

Answers

Answered by Equestriadash
23

Source cσde:

str1 = "w3resource"

str_dict = dict()

for i in str1:

   str_dict[i] = str1.count(i)

print("The required dictionary: ")

print()

print(str_dict)

Output:

{'w': 1, '3': 1, 'r': 2, 'e': 2, 's': 1, 'o': 1, 'u': 1, 'c': 1}

  • count() is a method that counts the number of occurrences of the character specified in brackets.
Answered by aditya881653
0

Explanation:

Please mark as brainiest answer

Attachments:
Similar questions