I have a list called pairs.
pairs = [("a", 1), ("b", 2), ("c", 3)]
And I can access elements as:
for x in pairs:
print x
which gives output like:
('a', 1) ('b', 2) ('c', 3)
But I want to access each element in each pair, like in c++, if we use pair<string, int>
we are able to access, first element and second element by x.first
, and x.second
.eg.
x = make_pair("a",1)
x.first= 'a'
x.second= 1
How can I do the same in python?
tuple
) and then you can look up the documentation, or already know from having followed a tutorial. – Klapp