Skip to content

Instantly share code, notes, and snippets.

@roman-on
Created May 17, 2020 23:10
Show Gist options
  • Save roman-on/5d1f81b9e591d2b56adc742a0b379ecf to your computer and use it in GitHub Desktop.
Save roman-on/5d1f81b9e591d2b56adc742a0b379ecf to your computer and use it in GitHub Desktop.
"""
The function accepts two parameters of the type Tuple as parameters.
The function returns a Tuple containing all the pairs that can be created from the passed-out Tuple organs.
Instructions:
To represent all the pairs, pairs of organs were also returned in the reverse order.
For example: The couple (1, 4) will be returned in addition to the couple (4, 1).
Examples of running the mult_tuple function:
first_tuple = (1, 2)
second_tuple = (4, 5)
mult_tuple(first_tuple, second_tuple)
# OUTPUT:
((1, 4), (4, 1), (1, 5), (5, 1), (2, 4), (4, 2), (2, 5), (5, 2))
############
first_tuple = (1, 2, 3)
second_tuple = (4, 5, 6)
mult_tuple(first_tuple, second_tuple)
# OUTPUT:
((1, 4), (1, 5), (1, 6), (2, 4), (2, 5), (2, 6), (3, 4), (3, 5), (3, 6), (4, 1), (5, 1), (6, 1), (4, 2), (5, 2), (6, 2), (4, 3), (5, 3), (6, 3))
"""
# The function accepts two parameters of the type Tuple as parameters.
# The function returns a Tuple containing all the pairs that can be created from the passed-out Tuple organs.
def mult_tuple(tuple1, tuple2):
result = [] # Making a new variable list
z = len(tuple1) # Taking the tuple length
i = 0
while i < z: # Till z i bigger than i it works
z -= 1 # Substract from z
for num in range (len(tuple1)): # Number in tuple length counting
a = tuple1[z], tuple2[num] # Tuplez counting by z, tuple2 counting by num
result.append(a) # Adding the result from variable a to final "result"
result.append(a[::-1]) # Adding the reverve version of a result to final "result"
b = tuple(result) # Converting the result from list to tuple
return b # Returning the final result as tuple already
def main():
<call the function>
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment