Python Forum
Unable to print the exact Float values when I convert LIST to Sequence of Tuples?
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to print the exact Float values when I convert LIST to Sequence of Tuples?
#1
Hi, Smile I have the following LIST in python, I am trying to convert it from this format to SEQUENCE OF TUPLES. I am able to convert it into a tuple but unable to get the desired output. Can someone please go through the code I have mentioned below ? Smile

List_to_be_converted = sf
sf = ['4.1', '4.2', '4.3', '4.4', '4.5', '4.6', '4.7'] **sad** 
#code to convert #
convert = tuple((float(x[0]), ) for x in sf)
#output after running the code
convert = ((4.0,), (4.0,), (4.0,), (4.0,), (4.0,), (4.0,), (4.0,))

Expected output = ((4.1,), (4.2,), (4.3,), (4.4,), (4.5,), (4.6,), (4.7,))
I am unable to see the decimal values of the output. Wall
Thank you a lot for your time
Reply
#2
convert = tuple((float(x),) for x in sf)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  remove duplicates from dicts with list values wardancer84 27 979 May-27-2024, 04:54 PM
Last Post: wardancer84
  python calculate float plus float is incorrect? sirocawa 6 570 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  unable to remove all elements from list based on a condition sg_python 3 600 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Copying the order of another list with identical values gohanhango 7 1,328 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,406 Nov-03-2023, 05:35 PM
Last Post: huzzug
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 577 Oct-17-2023, 09:46 AM
Last Post: tomciodev
Question in this code, I input Key_word, it can not find although all data was exact Help me! duchien04x4 3 1,172 Aug-31-2023, 05:36 PM
Last Post: deanhystad
  Comparing List values to get indexes Edward_ 7 1,378 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  How do you get Python to print just one value in a list? 357mag 3 1,125 May-17-2023, 09:52 PM
Last Post: rob101
  Print names in x-axis of a time-series values hobbyist 4 1,337 Apr-22-2023, 09:29 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020