For Python 3 onlySolutiondef names dict list1 while True
For Python 3 only
Solution
def names():
dict = {}
list1 = []
while (True) :
name = input(\"Enter next name: \")
if(name == \"\") :
list1 = list(dict.keys())
list1.sort()
print (len(list1))
print (list1)
else :
dict[name.capitalize()] = 1
Here dict1 is a dictionary. We can use the property of keys being distinct in a dictionary. Also, we use the property of lists having able to sort with just a function.
We use the capitalize function to convert all strings to capitalized form to consider the case-insensitive strings.
We check the accepted string if it is empty. If empty then we move the keys into the list. We sort this list and then print the list count and then the list itself.
![For Python 3 onlySolutiondef names(): dict = {} list1 = [] while (True) : name = input(\ For Python 3 onlySolutiondef names(): dict = {} list1 = [] while (True) : name = input(\](/WebImages/6/for-python-3-onlysolutiondef-names-dict-list1-while-true-988442-1761508015-0.webp)