0

I am trying to take a list of decimals

list1=[0.0020361512, 0.000825494, 0.002264453, 0.0020216484, 0.0008741686, 0.0018512862]

and get

0.0020361512
0.000825494
0.002264453
0.0020216484
0.0008741686 
0.0018512862

Are there any suggestions for this? The lists I will be running very in length from 1 to 190 decimals in the list.

Thank you!

Mustafa Aydın
  • 17,645
  • 4
  • 15
  • 38
  • 4
    what about `for value in list1: print(value)` ? – azro Jan 27 '22 at 18:28
  • 1
    It's not clear what you're asking. Are you trying to print the items line-by-line, or store them in a column format instead of a row format? What have you tried and what went wrong with your attempts? – G. Anderson Jan 27 '22 at 18:30
  • Hi! That was perfect. I am trying to print the items line-by-line so that I can copy and paste into a Excel document. Thanks! – Marisa Sandoval Jan 27 '22 at 18:35
  • If your goal is to get the numbers into excel you may want to consider [writing them to a file](https://stackoverflow.com/a/16131269/16450169) instead – 0x263A Jan 27 '22 at 18:44
  • print(*list1, sep='\n') – jsbueno Jan 27 '22 at 18:47

1 Answers1

0

I'm assuming you are trying to produce formatted text output in which case maybe this code will help you

list1=[0.0020361512, 0.000825494, 0.002264453, 0.0020216484, 0.0008741686, 0.0018512862]

# format floats into strings
# miniformat language - https://docs.python.org/3/library/string.html#format-specification-mini-language
# {:8.6f} => float with width of 8 and 6 decimal places
# {:.12f} => float with 12 decimal places
# for more complicated versions - check the python docs
decs = ['{:.12f}'.format(dec) for dec in list1]

# add a newline to each string and join together into a single text outpu
output = "\n".join(decs)

# print
print(output)

# or write to a file
with open("C:/Temp/output.txt", "w", encoding="utf8") as fpt:
    fpt.write(output)

this produces output like

0.002036151200
0.000825494000
0.002264453000
0.002021648400
0.000874168600
0.001851286200
woollypig
  • 51
  • 1
  • 4