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
  Assigning multiple values using tuple sivacg 2 61 2 hours ago
Last Post: perfringo
  Updating dictionary with tuple Mark17 2 70 10 hours ago
Last Post: Mark17
  Python Error- TypeError: ('Params must be in a list, tuple, or Row', 'HY000') DarkCoder2020 3 226 Jul-29-2020, 12:02 AM
Last Post: Larz60+
  Turn coordinates in string into a tuple Kolterdyx 3 177 Jun-10-2020, 05:04 AM
Last Post: buran
  How to append a tuple full of records to a dbf file in Python? DarkCoder2020 4 283 May-29-2020, 02:40 PM
Last Post: DarkCoder2020
  item from a line to list however when i print the line instead of words i get letters Sutsro 5 286 Apr-22-2020, 02:39 PM
Last Post: deanhystad
  how to get the keys in a named tuple Skaperen 5 353 Mar-25-2020, 09:51 PM
Last Post: Skaperen
  TypeError: 'tuple' object is not callable Chuck_Norwich 2 511 Feb-29-2020, 08:23 PM
Last Post: Chuck_Norwich
  'tuple' object has no attribute 'data' gregpederseng 2 519 Feb-25-2020, 08:01 PM
Last Post: gregpederseng
  Get the codemap combinations but got tuple index out of range haganmao 1 318 Feb-21-2020, 02:51 AM
Last Post: michael1789

Forum Jump:


Users browsing this thread: 1 Guest(s)