Skip to content
Sign upLog in
← Back to Community

How do I make it so that if two elements are same, I print ........

Profile icon
OldWizard209

How do I make it so that if two elements are same, I print 'No one was ejected'. I am referring from line 111 to 158 in file cafeteria.py .

Voters
Profile icon
Huan-XinXin
Profile icon
OldWizard209
Comments
hotnewtop
Profile icon
RYANTADIPARTHI

solution

maybe check them from the list view.

def lists(lists): if lists[0] == lists[1]: print('something') print(lists(['something', 'something']))

like that.

Profile icon
OldWizard209

Hi

@RYANTADIPARTHI
, just wanted to ask, why did your anger test post get locked, It was pretty cool....

Profile icon
RYANTADIPARTHI

@abdullahrajput9
yeah, i don't know why. no mod explained anything.

Profile icon
RedPandaCode

Wouldn't you just have an if statement? like if blank and blank are the same then you return true and if you return true then you would write your text. IDK I don't do Python.

Profile icon
Highwayman

Maybe make a function?

def count_of(el, arr): count = 0 for it in arr: if it == el: count = count + 1 return count # ... if count_of(vote, votes) == 2: # blah
Profile icon
JasonLiu19

I would create a new function:

def findtie(listf):

Then, we declare a variable inside that called greatst

greatst=max(listf)

Next, we iterate over the list and append any number equal to greatst another list.

maxs=[] for i in range (listf): if(listf[i]==greatst): maxs.append(listf[i])

Then, we check if there are multiple items in maxs.

if(len(maxs)>1): return 0 else: return maxs[0]

To implement the function:

if(findtie(votes)==0): #tie stuff else: #not tie stuff

Also:

for votes in votes:

Might not want to do that...