Python 2, 45 bytes
A mix of my initial solution and @ovs'.
lambda*a:map(lambda x,y:max(x,y)*-~(x==y),*a)
Python 2, 49 bytes
lambda x,y:[max(a,b)*-~(a==b)for a,b in zip(x,y)]
Python 2, 46 bytes
@ovs suggested this method to save 3 bytes.
lambda*x:[max(a,b)*-~(a==b)for a,b in zip(*x)]
#How?
How?
First off, we pair the corresponding elements, by using either * or zip(). That allows us to do our further golfing by working either with a map or a list comprehension.
The cool trick in this answer is this part: max(x,y)*-~(x==y). How does that work? - Well, as most of you already know, Python auto-converts bool values to integers when they are used in arithmetic operations. Hence, (x==y) gets evaluated as 1, if the condition is met. However, if the two values are not equal, it returns 0 instead. Then, the bitwise operation -~ increments the value returned from the bool by 1, giving us either 2 or 1. max(a,b) gives the maximum value of the pair and * multiplies it by the value returned above (so it gets multiplied by 2 only if they are equal, in which case max() returns the value of both).
This is based on the fact that the sum of two equal numbers is in fact either of them doubled, and kind of "abuses" Python's bool class being a subclass of int.
Python 2, 45 bytes
A mix of my initial solution and @ovs'.
lambda*a:map(lambda x,y:max(x,y)*-~(x==y),*a)
Python 2, 49 bytes
lambda x,y:[max(a,b)*-~(a==b)for a,b in zip(x,y)]
Python 2, 46 bytes
@ovs suggested this method to save 3 bytes.
lambda*x:[max(a,b)*-~(a==b)for a,b in zip(*x)]
#How?
First off, we pair the corresponding elements, by using either * or zip(). That allows us to do our further golfing by working either with a map or a list comprehension.
The cool trick in this answer is this part: max(x,y)*-~(x==y). How does that work? - Well, as most of you already know, Python auto-converts bool values to integers when they are used in arithmetic operations. Hence, (x==y) gets evaluated as 1, if the condition is met. However, if the two values are not equal, it returns 0 instead. Then, the bitwise operation -~ increments the value returned from the bool by 1, giving us either 2 or 1. max(a,b) gives the maximum value of the pair and * multiplies it by the value returned above (so it gets multiplied by 2 only if they are equal, in which case max() returns the value of both).
This is based on the fact that the sum of two equal numbers is in fact either of them doubled, and kind of "abuses" Python's bool class being a subclass of int.
Python 2, 45 bytes
A mix of my initial solution and @ovs'.
lambda*a:map(lambda x,y:max(x,y)*-~(x==y),*a)
Python 2, 49 bytes
lambda x,y:[max(a,b)*-~(a==b)for a,b in zip(x,y)]
Python 2, 46 bytes
@ovs suggested this method to save 3 bytes.
lambda*x:[max(a,b)*-~(a==b)for a,b in zip(*x)]
How?
First off, we pair the corresponding elements, by using either * or zip(). That allows us to do our further golfing by working either with a map or a list comprehension.
The cool trick in this answer is this part: max(x,y)*-~(x==y). How does that work? - Well, as most of you already know, Python auto-converts bool values to integers when they are used in arithmetic operations. Hence, (x==y) gets evaluated as 1, if the condition is met. However, if the two values are not equal, it returns 0 instead. Then, the bitwise operation -~ increments the value returned from the bool by 1, giving us either 2 or 1. max(a,b) gives the maximum value of the pair and * multiplies it by the value returned above (so it gets multiplied by 2 only if they are equal, in which case max() returns the value of both).
This is based on the fact that the sum of two equal numbers is in fact either of them doubled, and kind of "abuses" Python's bool class being a subclass of int.
Python 2, 45 bytes
A mix of my initial solution and @ovs'.
lambda*a:map(lambda x,y:max(x,y)*-~(x==y),*a)
Python 2, 49 bytes
lambda x,y:[max(a,b)*-~(a==b)for a,b in zip(x,y)]
Python 2, 46 bytes
@ovs suggested this method to save 3 bytes.
lambda*x:[max(a,b)*-~(a==b)for a,b in zip(*x)]
#How?
First off, we pair the corresponding elements, by using either * or zip(). That allows us to do our further golfing by working either with a map or a list comprehension.
The cool trick in this answer is this part: max(x,y)*-~(x==y). How does that work? - Well, as most of you already know, Python auto-converts bool values to integers when they are used in arithmetic operations. Hence, (x==y) gets evaluated as 1, if the condition is met. However, if the two values are not equal, it returns 0 instead. Then, the bitwise operation -~ increments the value returned from the bool by 1, giving us either 2 or 1. max(a,b) gives the maximum value of the pair and * multiplies it by the value returned above (so it gets multiplied by 2 only if they are equal, in which case max() returns the value of both).
This is based on the fact that the sum of two equal numbers is in fact either of them doubled, and kind of "abuses" Python's "semi-weak" typesbool class being a subclass of int.
Python 2, 45 bytes
A mix of my initial solution and @ovs'.
lambda*a:map(lambda x,y:max(x,y)*-~(x==y),*a)
Python 2, 49 bytes
lambda x,y:[max(a,b)*-~(a==b)for a,b in zip(x,y)]
Python 2, 46 bytes
@ovs suggested this method to save 3 bytes.
lambda*x:[max(a,b)*-~(a==b)for a,b in zip(*x)]
#How?
First off, we pair the corresponding elements, by using either * or zip(). That allows us to do our further golfing by working either with a map or a list comprehension.
The cool trick in this answer is this part: max(x,y)*-~(x==y). How does that work? - Well, as most of you already know, Python auto-converts bool values to integers when they are used in arithmetic operations. Hence, (x==y) gets evaluated as 1, if the condition is met. However, if the two values are not equal, it returns 0 instead. Then, the bitwise operation -~ increments the value returned from the bool by 1, giving us either 2 or 1. max(a,b) gives the maximum value of the pair and * multiplies it by the value returned above (so it gets multiplied by 2 only if they are equal, in which case max() returns the value of both).
This is based on the fact that the sum of two equal numbers is in fact either of them doubled, and kind of "abuses" Python's "semi-weak" types.
Python 2, 45 bytes
A mix of my initial solution and @ovs'.
lambda*a:map(lambda x,y:max(x,y)*-~(x==y),*a)
Python 2, 49 bytes
lambda x,y:[max(a,b)*-~(a==b)for a,b in zip(x,y)]
Python 2, 46 bytes
@ovs suggested this method to save 3 bytes.
lambda*x:[max(a,b)*-~(a==b)for a,b in zip(*x)]
#How?
First off, we pair the corresponding elements, by using either * or zip(). That allows us to do our further golfing by working either with a map or a list comprehension.
The cool trick in this answer is this part: max(x,y)*-~(x==y). How does that work? - Well, as most of you already know, Python auto-converts bool values to integers when they are used in arithmetic operations. Hence, (x==y) gets evaluated as 1, if the condition is met. However, if the two values are not equal, it returns 0 instead. Then, the bitwise operation -~ increments the value returned from the bool by 1, giving us either 2 or 1. max(a,b) gives the maximum value of the pair and * multiplies it by the value returned above (so it gets multiplied by 2 only if they are equal, in which case max() returns the value of both).
This is based on the fact that the sum of two equal numbers is in fact either of them doubled, and kind of "abuses" Python's bool class being a subclass of int.
Python 2, 45 bytes
A mix of my initial solution above and @ovs'.
lambda*a:map(lambda x,y:max(x,y)*-~(x==y),*a)
Python 2, 49 bytes
lambda x,y:[max(a,b)*-~(a==b)for a,b in zip(x,y)]
Python 2, 46 bytes
@ovs suggested this method to save 3 bytes.
lambda*x:[max(a,b)*-~(a==b)for a,b in zip(*x)]
#How?
First off, we pair the corresponding elements, by using either * or zip(). That allows us to do our further golfing by working either with a map or a list comprehension.
The cool trick in this answer is this part: max(x,y)*-~(x==y). How does that work? - Well, as most of you already know, Python auto-converts bool values to integers when they are used in arithmetic operations. Hence, (x==y) gets evaluated as 1, if the condition is met. However, if the two values are not equal, it returns 0 instead. Then, the bitwise operation -~ increments the value returned from the bool by 1, giving us either 2 or 1. max(a,b) gives the maximum value of the pair and * multiplies it by the value returned above (so it gets multiplied by 2 only if they are equal, in which case max() returns the value of both).
This is based on the fact that the sum of two equal numbers is in fact either of them doubled, and kind of "abuses" Python's "semi-weak" types.
Python 2, 45 bytes
A mix of my solution above and @ovs'.
lambda*a:map(lambda x,y:max(x,y)*-~(x==y),*a)
Python 2, 49 bytes
lambda x,y:[max(a,b)*-~(a==b)for a,b in zip(x,y)]
Python 2, 46 bytes
@ovs suggested this method to save 3 bytes.
lambda*x:[max(a,b)*-~(a==b)for a,b in zip(*x)]
#How?
First off, we pair the corresponding elements, by using either * or zip(). That allows us to do our further golfing by working either with a map or a list comprehension.
The cool trick in this answer is this part: max(x,y)*-~(x==y). How does that work? - Well, as most of you already know, Python auto-converts bool values to integers when they are used in arithmetic operations. Hence, (x==y) gets evaluated as 1, if the condition is met. However, if the two values are not equal, it returns 0 instead. Then, the bitwise operation -~ increments the value returned from the bool by 1, giving us either 2 or 1. max(a,b) gives the maximum value of the pair and * multiplies it by the value returned above (so it gets multiplied by 2 only if they are equal, in which case max() returns the value of both).
This is based on the fact that the sum of two equal numbers is in fact either of them doubled, and kind of "abuses" Python's "semi-weak" types.
Python 2, 45 bytes
A mix of my initial solution and @ovs'.
lambda*a:map(lambda x,y:max(x,y)*-~(x==y),*a)
Python 2, 49 bytes
lambda x,y:[max(a,b)*-~(a==b)for a,b in zip(x,y)]
Python 2, 46 bytes
@ovs suggested this method to save 3 bytes.
lambda*x:[max(a,b)*-~(a==b)for a,b in zip(*x)]
#How?
First off, we pair the corresponding elements, by using either * or zip(). That allows us to do our further golfing by working either with a map or a list comprehension.
The cool trick in this answer is this part: max(x,y)*-~(x==y). How does that work? - Well, as most of you already know, Python auto-converts bool values to integers when they are used in arithmetic operations. Hence, (x==y) gets evaluated as 1, if the condition is met. However, if the two values are not equal, it returns 0 instead. Then, the bitwise operation -~ increments the value returned from the bool by 1, giving us either 2 or 1. max(a,b) gives the maximum value of the pair and * multiplies it by the value returned above (so it gets multiplied by 2 only if they are equal, in which case max() returns the value of both).
This is based on the fact that the sum of two equal numbers is in fact either of them doubled, and kind of "abuses" Python's "semi-weak" types.