How to get first line of a tuple and the third item in its tuple. Need Help, Anybody? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to get first line of a tuple and the third item in its tuple. Need Help, Anybody? (/thread-18507.html) |
How to get first line of a tuple and the third item in its tuple. Need Help, Anybody? - SukhmeetSingh - May-20-2019 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: I only need this single value to print: 0.0656498375731458
RE: How to pick first line and their third number. Need Help, Anybody? - Yoriz - May-20-2019 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 buy the first [0] would get the first tuple and the second [2] would get its 3rd item.
RE: How to get first line of a tuple and the third item in its tuple. Need Help, Anybody? - SukhmeetSingh - May-21-2019 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__' RE: How to get first line of a tuple and the third item in its tuple. Need Help, Anybody? - buran - May-21-2019 Please, use BBcode as advised. RE: How to get first line of a tuple and the third item in its tuple. Need Help, Anybody? - SukhmeetSingh - May-21-2019
RE: How to get first line of a tuple and the third item in its tuple. Need Help, Anybody? - avorane - May-21-2019 Hello, Can you send all code in module, please? Best Regards, Nicolas TATARENKO |