how to find the repeated item of a tuple？ tup=（2，4，5，6，2，3，4，4，7，8，4，3，2） expecting output：4
for i in tup: if tup.count(i) > 1: print('REPEATED') I think this is the shortest solution
print(tup.count(4)) # outputs 4 because there are 4 fours
This is perfect : https://code.sololearn.com/cQMR30h0jaYy/?ref=app #Don't forget to like the code. 😉😁😉
@Tobi Yes! I have just started learning python. Will learn every module completely. Oh! And they does not teach lambda or Linq in C# here. You will need to learn it on the MSDN. Very few programmers use these techniques. So less tutorials out there for advance programming. 😔
@Tobi Wow! There is also lambda expression in python too!! Lambda makes codes much smaller and efficient. I always use lambda expression in C#. 😉
Perhaps use a loop that would find out how many repeats a number has (maybe with an array). Then you can just find the number with the most repeats. Or use 2 nested loops, one to check number of repeats, one to go through the other loop again to see if there's a larger repeat. (easier method but O(n^2) complexity.) Edit: @mary sorry I've never done python so i wouldn't be able to help with writing the actual code.
@Cyrus: Yeah, I love all these concepts from functional programming too. Python has quite a few cool concepts like these, check out the functional programming module in the course, if you like. SoloLearn really did a great job introducing them. I will definitely look into C#, when the time has come.
This gives you one of the list elements, which are repeated the most. Essentially one line and not to inelegant: https://code.sololearn.com/c0p3TH5wQ3w9/?ref=app
Why 4 and not 2? 2 is also repeated.
@Tobi maybe the question wants the most repeated.
@Rrestoring faith it's too complicated for me……
okay，thank you all
#This finds the repeated items in a tuple.... tup= (1,2,3,4,4,5,5,12,12,12,12,1,3,2,4, "my", "my", "hi", "hi", "hello") rep= for i in tup: if tup.count(i)>1: rep.append(i) else: continue for x in rep: while rep.count(x)>1: rep.remove(x) print("Repeated items:",tuple(rep))
How do I generate a list with <N> unique elements randomly selected from another (already existing) list?
Given three integer matrices A(m*n),B(m*n) and C(m*n) . Print the one with more zero elements. beside code
I'm coding this for hours & can't make the value of the 5 random numbers round off to 2 decimal places like in the examples
Overloading + operator