imagine I have a tuple in which, among other things, a list is stored.
for example:
t = (1, 2, 3, 4 [5, 6, 7])
Well, I want all the numbers they are saved in tuple and list. How do I do that? In separate I know how to get the numbers they are saved in tuple. I would just unpack the tuple and to get all numbers, which is saved in lis, I would just iterate over it. But in this situation I don't know what I have to do.
Any ideas?
For more details
def work_with_tuple(my_tuple = None):
count_items = len(my_tuple)
if count_items == 2:
first_item, second_item = my_tuple
print "first_item", first_item
print "second_item", second_item
if count_items == 3:
first_item, second_item, third_item = my_tuple
print "first_item", first_item
print "second_item", second_item
# But I have to know, that 'third_item' is a list.
# Should I check every unpacked item if it is a list?
# I think my idea it doesn't sound elegance.
one, two = third_item
print "one", one
print "two", two
print "run first"
print "---------"
# I call the function with easy tuple
work_with_tuple(my_tuple = (2, 3))
# output: first_item 2
# second_item 3
print ""
print "run second"
print "----------"
# I call the function with nested tuple
work_with_tuple(my_tuple = (2, 3, [4, 6]))
# output: first_item 2
# second_item 3
# one 4
# two 6