tuples

How do I get integers from a tuple in Python?

笑着哭i 提交于 2020-12-01 07:13:02
问题 I have a tuple with two numbers in it, I need to get both numbers. The first number is the x-coordinate, while the second is the y-coordinate. My pseudo code is my idea about how to go about it, however I'm not quite sure how to make it work. pseudo code: tuple = (46, 153) string = str(tuple) ss = string.search() int1 = first_int(ss) int2 = first_int(ss) print int1 print int2 int1 would return 46, while int2 would return 153. 回答1: int1, int2 = tuple 回答2: The other way is to use array

How do I get integers from a tuple in Python?

穿精又带淫゛_ 提交于 2020-12-01 07:12:05
问题 I have a tuple with two numbers in it, I need to get both numbers. The first number is the x-coordinate, while the second is the y-coordinate. My pseudo code is my idea about how to go about it, however I'm not quite sure how to make it work. pseudo code: tuple = (46, 153) string = str(tuple) ss = string.search() int1 = first_int(ss) int2 = first_int(ss) print int1 print int2 int1 would return 46, while int2 would return 153. 回答1: int1, int2 = tuple 回答2: The other way is to use array

Get tuples with max value from each key from a list

我怕爱的太早我们不能终老 提交于 2020-11-24 19:13:23
问题 I have a list of tuples like this: [(1, 0), (2, 1), (3, 1), (6, 2), (3, 2), (2, 3)] I want to keep the tuples which have the max first value of every tuple with the same second value. For example (2, 1) and (3, 1) share the same second (key) value, so I just want to keep the one with the max first value -> (3, 1) . In the end I would get this: [(1, 0), (3, 1), (6, 2), (2, 3)] I don't mind at all if it is not a one-liner but I was wondering about an efficient way to go about this... 回答1: from

Get tuples with max value from each key from a list

帅比萌擦擦* 提交于 2020-11-24 19:07:08
问题 I have a list of tuples like this: [(1, 0), (2, 1), (3, 1), (6, 2), (3, 2), (2, 3)] I want to keep the tuples which have the max first value of every tuple with the same second value. For example (2, 1) and (3, 1) share the same second (key) value, so I just want to keep the one with the max first value -> (3, 1) . In the end I would get this: [(1, 0), (3, 1), (6, 2), (2, 3)] I don't mind at all if it is not a one-liner but I was wondering about an efficient way to go about this... 回答1: from

Get tuples with max value from each key from a list

房东的猫 提交于 2020-11-24 19:06:23
问题 I have a list of tuples like this: [(1, 0), (2, 1), (3, 1), (6, 2), (3, 2), (2, 3)] I want to keep the tuples which have the max first value of every tuple with the same second value. For example (2, 1) and (3, 1) share the same second (key) value, so I just want to keep the one with the max first value -> (3, 1) . In the end I would get this: [(1, 0), (3, 1), (6, 2), (2, 3)] I don't mind at all if it is not a one-liner but I was wondering about an efficient way to go about this... 回答1: from