Python Forum

Full Version: How to get first line of a tuple and the third item in its tuple. Need Help, Anybody?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have these values which I store in a:
a = ((1.425, 4.82145395112958, 0.0656498375731458)
    (1.39716316090366, 7.2, 0.102480129941483)
    (7.425, 4.82145395112958, 0.0656498375731458)
    (7.39716316090366, 7.2, 0.102480129941483)
    (7.425, -0.928546048870416, 0.0656498375731458)
    (7.39716316090366, 0.95, 0.102480129941483)
    (1.425, -0.928546048870416, 0.0656498375731458)
    (1.39716316090366, 0.95, 0.102480129941483))
what I'm doing:
print a[2]
Gives:
Output:
0.0656498375731458 0.102480129941483 0.0656498375731458 0.102480129941483 0.0656498375731458 0.102480129941483 0.0656498375731458 0.102480129941483
I only need this single value to print: 0.0656498375731458
Your sample of a is not a valid tuple in a tuple(missing , seperators), printing a[2] would not give the results shown.

a = ((1.425, 4.82145395112958, 0.0656498375731458),
    (1.39716316090366, 7.2, 0.102480129941483),
    (7.425, 4.82145395112958, 0.0656498375731458),
    (7.39716316090366, 7.2, 0.102480129941483),
    (7.425, -0.928546048870416, 0.0656498375731458),
    (7.39716316090366, 0.95, 0.102480129941483),
    (1.425, -0.928546048870416, 0.0656498375731458),
    (1.39716316090366, 0.95, 0.102480129941483))

print(a[0][2])
would give
Output:
0.0656498375731458
buy the first [0] would get the first tuple and the second [2] would get its 3rd item.
error:
Traceback (most recent call last):
File "D:\Py\check cartesian.py", line 26, in <module>
print a[0][2]
TypeError: 'float' object has no attribute '__getitem__'
Please, use BBcode as advised.
Error:
Traceback (most recent call last): File "D:\Py\check cartesian.py", line 26, in <module> print a[0][2] TypeError: 'float' object has no attribute '__getitem__'
Hello,

Can you send all code in module, please?

Best Regards,

Nicolas TATARENKO