user14382661
user14382661

Reputation:

How to access a tuple inside a tuple with a range in python?

I am working on a Playfair cipher project in python and I need to access a tuple which is inside a tuple it is a table in my programs context and I need to add letters in it but am confused on how I would navigate through it. When I mean navigate I mean, how to read the tuple inside the tuple to see how many letters are in each tuple, how to add a letters in each of the tuples and how to move on to the next tuple.

Here is the tuple inside a tuple that I am talking about:

                     self.__table = (tuple(table[0:5]), tuple(table[5:10]),
                     tuple(table[10:15]), tuple(table[15:20]),
                     tuple(table[20:25]))

Here is the link to the entire code if that helps (the one my professor gave me): https://gist.github.com/roshanlam/3d1d495c42a92ca96a961655b9276651

Upvotes: 0

Views: 209

Answers (1)

Cute Panda
Cute Panda

Reputation: 1498

Suppose a sample tuple of tuples is x as given below, then you can access individual elements like this:

x = ((1,6,0),(2,3),(4,9,6,5,10))
for item in x:
    print(len(item)) #length of item tuple
    for i in item:
        print(i) #prints individual elements of tuple

Upvotes: 1

Related Questions