+ 3

Why is there value.append(str??

I got this code somewhere on the internet today. I didn't understand why there was a string conversion with value.append(). Whatever input is feeded is not in str? Or why is it str(int?? And also why items = x for x in input(). I got the input part, but what about x. Is there any other way to represent this items? I'm a noob so your answers would help me to think in a different way. Thank you. https://code.sololearn.com/cOdB0qYx1CQa/?ref=app

21st May 2019, 7:20 AM
Akhil Padmanabhan
Akhil Padmanabhan - avatar
11 Answers
+ 2
~ swim ~ Thank you for your reply What is the parameter for stating list comprehension is the efficient way? Why did you call it efficient? And okay input gives a string understood. But what's exactly happening in the line? value.append(str(int(round(math.sqrt(2*c*float(d)/h))))) What is this line doing? Like from round i understood that whatever answer i get from math.sqrt(equation) is to be rounded off. Now this rounded off value is in the integer form only right? No?
21st May 2019, 8:28 AM
Akhil Padmanabhan
Akhil Padmanabhan - avatar
+ 1
at the end of your code, it's using join() which returns a concatenated string with an iterable and string u suggested. It gives a TypeError if iterable is not a string that's why its typecasted to a string. I don't understand the second part of your question, please make clear what you want to ask. Also in your code comment on the second line is wrong. Value is not set its an list.
21st May 2019, 7:52 AM
Yugabdh
Yugabdh - avatar
+ 1
input().split(str) input alway returns a string. str.split(str) always returns a list of substrings. [x for x in y] Is a special way to create lists. [x for x in input().split(str)] Is the same than input().split(str), it doesn't change anything.
21st May 2019, 8:05 AM
Seb TheS
Seb TheS - avatar
+ 1
Yugabdh Thank you for your reply You're talking about value.append(str(int(round(math.sqrt(2*c*float(d)/h))))) That whatever answer we get out of this has to converted into string before it goes through print (','.join(value)) Because this join() looks for strings and separates those with a ','?
21st May 2019, 8:32 AM
Akhil Padmanabhan
Akhil Padmanabhan - avatar
+ 1
~ swim ~ Thank you!! But still value.append(str(int(round(math.sqrt(2*c*float(d)/h))))) Why str(int( ?? The value rounded off is not an integer?
21st May 2019, 9:12 AM
Akhil Padmanabhan
Akhil Padmanabhan - avatar
+ 1
Oh greatttttt!!! ~ swim ~ thank you got it!!
21st May 2019, 10:06 AM
Akhil Padmanabhan
Akhil Padmanabhan - avatar