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
  unable to remove all elements from list based on a condition sg_python 3 377 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Copying the order of another list with identical values gohanhango 7 1,062 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,147 Nov-03-2023, 05:35 PM
Last Post: huzzug
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 427 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 972 Aug-31-2023, 05:36 PM
Last Post: deanhystad
  Comparing List values to get indexes Edward_ 7 1,083 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  How do you get Python to print just one value in a list? 357mag 3 967 May-17-2023, 09:52 PM
Last Post: rob101
  Print names in x-axis of a time-series values hobbyist 4 1,178 Apr-22-2023, 09:29 PM
Last Post: deanhystad
  convert string to float in list jacklee26 6 1,815 Feb-13-2023, 01:14 AM
Last Post: jacklee26
  Adding values with reduce() function from the list of tuples kinimod 10 2,514 Jan-24-2023, 08:22 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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