Answer to Question #341372 in Python for sandhya

Question #341372

Names and nicknames:

There are N persons in a society .You know the names and nicknames of all of the N people in society. Your task is to determine if there any two persons who have the same name and nickname

input:

The first line of input contains integer N

Each of next N lines contains two space separated strings denoting the name and nickname of person

output:

print YES if there is a pair of people with the same name and nickname otherwise print NO

i/p:

2

3

stephen steve

sato hanako

stephen steve

2

conan kun

subaro kun

o/p:

yes

no

i/P:

2

3

thomas cat

jerry mouse

johny bravo

3

nicolas tesla

saito san

nicolas tesla

o/p:

no

yes


1
Expert's answer
2022-05-15T16:59:21-0400
number_society = int(input('Enter the number of societies:'))
ans = []
for _ in range(number_society):
    num_people = int(input('Keep the number of people in societies:'))
    people_lst = [input() for _ in range(num_people)]
    # for _ in range(num_people):
    #     people_lst.append(input())
    ans.append('no' if len(set(people_lst)) == len(people_lst) else 'yes')
print(*ans, sep='\n')

INPUT/OUTPUT:
Enter the number of societies:2
Keep the number of people in societies:3
stephen steve
sato hanako
stephen steve
Keep the number of people in societies:2
conan kun
subaro kun
yes
no

Enter the number of societies:2
Keep the number of people in societies:3
thomas cat
jerry mouse
johny bravo
Keep the number of people in societies:3
nicolas tesla
saito san
nicolas tesla
no
yes

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS