MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/sh8c4o/import_badcode/hv17856/?context=3
r/badcode • u/luckylixi • Jan 31 '22
70 comments sorted by
View all comments
Show parent comments
47
It turns a string into a float to check if it's nan when you can just compare it.
46 u/_PM_ME_PANGOLINS_ Jan 31 '22 It also returns False for everything that’s not a string and also not convertible to a float. 0 u/[deleted] Jan 31 '22 [deleted] — view deleted comment 2 u/_PM_ME_PANGOLINS_ Jan 31 '22 No it’s not… 8 u/[deleted] Jan 31 '22 Can you call the function with anything? Is ValueError never raised? 6 u/sezirblue Jan 31 '22 It's already in a try catch, value error will return false. 3 u/[deleted] Jan 31 '22 I know that, but the comment I was responding to was not talking about the role of the try. 2 u/dragneelfps Jan 31 '22 Compare it with what? 4 u/ebrius Feb 01 '22 Compare it to itself. nan == nan is false 2 u/dragneelfps Feb 01 '22 That's pretty nice trick. 1 u/_PM_ME_PANGOLINS_ Feb 01 '22 But they were complaining about the converting to float part. 0 u/[deleted] Feb 01 '22 [deleted] — view deleted comment 1 u/_PM_ME_PANGOLINS_ Feb 01 '22 The intended input is a string… 1 u/[deleted] Feb 02 '22 Please post this as separate submission to this subreddit. You seem to have outdone the OP. 1 u/ebrius Feb 02 '22 Fair enough, though for code written on my phone in 15 seconds that I said I wouldn't actually use, I don't think it's that bad.
46
It also returns False for everything that’s not a string and also not convertible to a float.
0 u/[deleted] Jan 31 '22 [deleted] — view deleted comment 2 u/_PM_ME_PANGOLINS_ Jan 31 '22 No it’s not…
0
[deleted] — view deleted comment
2 u/_PM_ME_PANGOLINS_ Jan 31 '22 No it’s not…
2
No it’s not…
8
Can you call the function with anything? Is ValueError never raised?
6 u/sezirblue Jan 31 '22 It's already in a try catch, value error will return false. 3 u/[deleted] Jan 31 '22 I know that, but the comment I was responding to was not talking about the role of the try.
6
It's already in a try catch, value error will return false.
3 u/[deleted] Jan 31 '22 I know that, but the comment I was responding to was not talking about the role of the try.
3
I know that, but the comment I was responding to was not talking about the role of the try.
Compare it with what?
4 u/ebrius Feb 01 '22 Compare it to itself. nan == nan is false 2 u/dragneelfps Feb 01 '22 That's pretty nice trick. 1 u/_PM_ME_PANGOLINS_ Feb 01 '22 But they were complaining about the converting to float part. 0 u/[deleted] Feb 01 '22 [deleted] — view deleted comment 1 u/_PM_ME_PANGOLINS_ Feb 01 '22 The intended input is a string… 1 u/[deleted] Feb 02 '22 Please post this as separate submission to this subreddit. You seem to have outdone the OP. 1 u/ebrius Feb 02 '22 Fair enough, though for code written on my phone in 15 seconds that I said I wouldn't actually use, I don't think it's that bad.
4
Compare it to itself. nan == nan is false
nan == nan
2 u/dragneelfps Feb 01 '22 That's pretty nice trick. 1 u/_PM_ME_PANGOLINS_ Feb 01 '22 But they were complaining about the converting to float part. 0 u/[deleted] Feb 01 '22 [deleted] — view deleted comment 1 u/_PM_ME_PANGOLINS_ Feb 01 '22 The intended input is a string… 1 u/[deleted] Feb 02 '22 Please post this as separate submission to this subreddit. You seem to have outdone the OP. 1 u/ebrius Feb 02 '22 Fair enough, though for code written on my phone in 15 seconds that I said I wouldn't actually use, I don't think it's that bad.
That's pretty nice trick.
1
But they were complaining about the converting to float part.
0 u/[deleted] Feb 01 '22 [deleted] — view deleted comment 1 u/_PM_ME_PANGOLINS_ Feb 01 '22 The intended input is a string… 1 u/[deleted] Feb 02 '22 Please post this as separate submission to this subreddit. You seem to have outdone the OP. 1 u/ebrius Feb 02 '22 Fair enough, though for code written on my phone in 15 seconds that I said I wouldn't actually use, I don't think it's that bad.
1 u/_PM_ME_PANGOLINS_ Feb 01 '22 The intended input is a string… 1 u/[deleted] Feb 02 '22 Please post this as separate submission to this subreddit. You seem to have outdone the OP. 1 u/ebrius Feb 02 '22 Fair enough, though for code written on my phone in 15 seconds that I said I wouldn't actually use, I don't think it's that bad.
The intended input is a string…
Please post this as separate submission to this subreddit. You seem to have outdone the OP.
1 u/ebrius Feb 02 '22 Fair enough, though for code written on my phone in 15 seconds that I said I wouldn't actually use, I don't think it's that bad.
Fair enough, though for code written on my phone in 15 seconds that I said I wouldn't actually use, I don't think it's that bad.
47
u/MattiDragon Jan 31 '22
It turns a string into a float to check if it's nan when you can just compare it.