2

I have a two variable, a = ("0", "2", "0") b = ("Jenny", "Christy", "Monica") if I run the code

x = min(zip(a, b)) print(x) 

my output will be ('0', 'Jenny')

If I want the output- (('0', 'Jenny'),('0','Monica))- what should I do?

1
  • sorry about the edit, did't know min() works on string too. are you using python or python3 ? zip() is different in the two see stackoverflow.com/questions/31683959/… Commented Jun 11, 2021 at 8:55

3 Answers 3

2

In fact, you want the min of a:

>>> [(i, j) for i, j in zip(a, b) if i == min(a)] [('0', 'Jenny'), ('0', 'Monica')] 

If you compare each tuple then ('0', 'Jenny') < ('0', 'Monica')

Sign up to request clarification or add additional context in comments.

Comments

0
a = ("0", "2", "0") b = ("Jenny", "Christy", "Monica") x = list(zip(a, b)) output = [] for i in range(len(x)): if min(a) in x[i]: output.append(x[i]) print(output) 

Actually when your code finds two minimum values in a, then it compares the minimum value of b also and it finds 'Jenny' first letter J is smaller than 'Monica' first letter 'M'. Thats why it returns only one value

Comments

0
a = ("0", "2", "0") b = ("Jenny", "Christy", "Monica") x = () for i in range(len(a)): if a[i] == "0": x += (a[i],b[i]) print(x) #Brute force way. 

2 Comments

sorry to bother I'm on no question ban. Why do you think ff =['1c','2','3','4','5','6'] for i in ff: print(type(i), min(ff), type(min(ff))), gives 1c as minimum
Well, I was just trying to help. I thought it would be affected because it's a string. lol

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.