+ 4

Need help with a code.

Import random List=[2,3,4,5,6,7,8,9,10,"A","J","Q","K"] a=random.choice(list) b=random.choice(list) c=random.choice(list) d=random.choice(list) e=random.choice(list) f=random.choice(list) g=random.choice(list) on_table=[a,b,c,d,e,f,g,] **How to count the number of duplicates(pairs) from the on_table list?** For example if a=4 and d=4 to show 1 pair or if a=5, c=4 , d=5 and g=4 to show 2 pairs. I need an example and a explication(detailed or not). #Working on a poker game.(check my Playing Cards code if you want to see how it looks like)

10th Nov 2018, 4:18 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
5 Respostas
+ 5
Ok. You can try use set. Set is and i quote "is an unordered collection with no duplicate elements. " --Python3 documentation Here one example https://code.sololearn.com/cXQgpj292qnt/?ref=app
10th Nov 2018, 5:53 PM
Anya
Anya - avatar
+ 5
That is exactly what I needed! Thank you! 😘
10th Nov 2018, 6:01 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 4
just to be sure. Do you only want the quantity of duplicates? Edit: Or Do you want to know who is the pair of duplicates and total quantity.
10th Nov 2018, 5:08 PM
Anya
Anya - avatar
+ 4
Only the quantity of duplicates.
10th Nov 2018, 5:30 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 1
def duplicates(on_table): counter = [] for card in on_table: if on_table.count(card) > 1 and card not in counter: counter.append(card) return len(counter)
10th Nov 2018, 6:06 PM
Ulisses Cruz
Ulisses Cruz - avatar