Names and Nicknames in Python

Problem Statement:

It’s very simple, we need to find the number of strings equal to each other, and that’s it. This was the technical intro to the problem. Now, let’s see the actual problem. We are given some names and we need to find the number of pairs that exist. A pair means two names are equal to each other.

Code to find Names and Nicknames in Python:

t = int(input('Enter number of test cases: '))
for i in range(t):
    n = int(input('\nEnter number of people: '))
    names = []
    for j in range(n):
        names.append(input('Enter new name: '))
    count_ = []
    for i in names:
        count_.append(names.count(i))
    if max(count_)>1:
        print('Yes, there is 1 or more pair(s) exist')
    else:
        print('No pair exist')

Output:

Output for Names and Nicknames in Python

Also Read:

Share:

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@copyassignment.com Thank you