Click here to Skip to main content
15,568,965 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello
I have number of number sets and I want to find how many times each pair was repeated across all sets in python
Example
A = [1, 3, 5, 7, 9 ]
B = [ 3, 5, 10, 11 ]
C =  [1, 3, 5, 10, 11 ]

Wanted result :
pair [3, 5] = 3 times
Pair [1, 5] = 2 times
Pair [10, 11] = 2 times

Also I want results containing pairs repeated more than 1 time

Also I want the pairs arranged from the most repeated to the least repeated

What I have tried:

Python
From collections 
 Import counter
 Find A&B&C
Print
Posted
Updated 27-Feb-22 8:42am
v2
Comments
OriginalGriff 24-Feb-22 5:42am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?
Where are you stuck?
What help do you need?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.

Use the "Improve question" widget to edit your question and provide better information.
Richard MacCutchan 24-Feb-22 6:02am    
The pair[1,5] does not occur in your samples. So, are you looking for any two numbers that occur more than once, or only those numbers that occur as a strict pair?
Andre Oosthuizen 24-Feb-22 15:34pm    
What I have tried: --- not much apart from copying and pasting an assignment question.
merano99 24-Feb-22 18:33pm    
If a Python solution is desired, why is the question also marked as C++?
Completely different solutions could possibly be considered here.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Think about how you would do it manually: you would create a list of all possible "pairs" for each set, and then look for matches across all three: So I'd start by thinking about how to do that. Hint: once you have assembled the pairs, sorting each set makes comparing them a lot easier!
Or maybe you'd look for all the matching numbers in all three sets, and then assemble pairs from that.
Part of the point of the task is to get you thinking about how to solve problems - so get thinking!

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
v2
Your question is not quite clear, but... assuming that you want to get number of occurencies of each number, you can try this:

Python
A = [1, 3, 5, 7, 9]
B = [ 3, 5, 10, 11]
C = [1, 3, 5, 10, 11]
#create list of common numbers
comnum = A
comnum.extend(B)
comnum.extend(C)
#create a dictionary object with the number of occurencies of each number
noofoc = dict((i,comnum.count(i)) for i in set(comnum))
#find numbers with more than one occurence
mulnum = dict(filter(lambda e:e[1]>1, noofoc.items()))
print(mulnum)
#prints: {1: 2, 3: 3, 5: 3, 10: 2, 11: 2}


The rest of work is up to you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900