Given a list of integers, generate the list of the corresponding floats.
karthik.c 6 Light Poster
Recommended Answers
Jump to Post— scru 909you can use a list comprehension:
new_list = [float(integral) for integral in old_list]
Jump to Post— scru 909Then you would do:
l1 = [1,2,3,4,5] l2 = [float(i) for i in l1] print l2[float(i) for i in l1] is what is known as a list comprehension. You should be already familiar with the for loop which loops through each integer in the list and …
All 8 Replies
scru 909 Posting Virtuoso Featured Poster
karthik.c 6 Light Poster
scru 909 Posting Virtuoso Featured Poster
Ene Uran 638 Posting Virtuoso
karthik.c 6 Light Poster
Ene Uran 638 Posting Virtuoso
jrcagle 77 Practically a Master Poster
scru 909 Posting Virtuoso Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.