Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to get first line of a tuple and the third item in its tuple. Need Help, Anybody?
#1
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
Yoriz wrote May-20-2019, 09:31 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#2
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.
Quote
#3
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__'
Quote
#4
Please, use BBcode as advised.
Quote
#5
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__'
Quote
#6
Hello,

Can you send all code in module, please?

Best Regards,

Nicolas TATARENKO
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Failed to insert record into MySQL table.Python type tuple cannot be converted farah97 3 230 Dec-26-2019, 02:01 PM
Last Post: buran
  Pass Tuple as a Slice nagymusic 2 156 Dec-12-2019, 04:42 AM
Last Post: nagymusic
  Being explicit about the items inside a tuple argument rudihammad 3 177 Dec-04-2019, 08:10 AM
Last Post: perfringo
  parenthesis around a tuple of literals in a for Skaperen 2 237 Aug-25-2019, 03:00 AM
Last Post: Skaperen
  getopt with tuple not working proper Frank123456 0 180 Aug-21-2019, 12:46 PM
Last Post: Frank123456
  Code syntax with underscore and assigning to a tuple santoshbwn 1 267 Jun-24-2019, 12:05 PM
Last Post: ThomasL
  Arrange list of tuple using loop batchenr 7 582 Jun-16-2019, 03:24 PM
Last Post: Abdullah
  Call a Function contained in a Tuple SamGer 7 514 Jun-14-2019, 05:00 PM
Last Post: ThomasL
  Question on Tuple SamGer 2 303 Jun-03-2019, 02:14 PM
Last Post: DeaD_EyE
  AttributeError: 'tuple' object has no attribute 'interface' Kim6071 1 980 May-26-2019, 07:54 AM
Last Post: heiner55

Forum Jump:


Users browsing this thread: 1 Guest(s)