Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 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
Quote
#2
convert = tuple((float(x),) for x in sf)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Attach sentiment to each word in a list of tuples Casper 3 938 Oct-13-2018, 02:02 PM
Last Post: ojirgl
  Fibonacci sequence Darbandiman123 2 57 Sep-26-2018, 02:32 PM
Last Post: Darbandiman123
  Unable to send text via sendkeys SamLearnsPython 1 137 Sep-08-2018, 11:19 AM
Last Post: SamLearnsPython
  unable to run unix command using spur purnima1 11 256 Sep-07-2018, 07:57 AM
Last Post: purnima1
  How to trim a float number? microphone_head 5 196 Aug-20-2018, 08:52 PM
Last Post: perfringo
  [Help] How to print elements from list of lists? vanicci 2 131 Aug-12-2018, 09:48 AM
Last Post: vanicci
  sorting a list of tuples based on date bluefrog 2 137 Aug-10-2018, 02:31 AM
Last Post: ichabod801
  is it float or is it int? Skaperen 2 163 Aug-06-2018, 06:36 AM
Last Post: Skaperen
  float to int conversion Skaperen 5 189 Aug-05-2018, 01:24 PM
Last Post: Windspar
  Print element of list if string included = element of another list silfer 4 267 Jul-30-2018, 10:29 AM
Last Post: silfer

Forum Jump:


Users browsing this thread: 1 Guest(s)