You can convert your integer to a string, and create a list using list comprehension where you iterate through every character of your "string" and cast it back to a digit: n = ANY_NUMBER_HERE digits = [int(i) for i in (str(n) if n >= 0 else str(n)[1:])] Note that this code above also checks if the original number is negative so it doesn't include the negative sign.
Use the same technique as described in the video. However, instead of adding each digit you extract to a single list, check if the digit is even using digit % 2 == 0. If it is odd, this should be false, but if it is even, it should be true.
Java code is attached below. This shows the use of either Arrays or ArrayLists for accomplishing this: gist.github.com/pr28416/eae736a9c27dc3263100c13d4a6bfbc3 Hope this helps.
Helped me in ai practical exam. Thanks :D
Thank you for your help, coz I have been looking for this since yesterday to find second digit, but I got it from you channel.
thx dude, you helped me solve the Leetcode question #1281
brooo thank you so much, i had trouble understanding this but you have helped me alot! Thanks!
Hey man! When I use the same logic, only the first element of the list is getting displayed. Please help me..
or
my_int = 123456789
my_list = [int(x) for x in str(my_int)]
print(my_list)
so mod in python is the DIV library routine in pseudocode?
What's the simpler, less mathmatical way?
You can convert your integer to a string, and create a list using list comprehension where you iterate through every character of your "string" and cast it back to a digit:
n = ANY_NUMBER_HERE
digits = [int(i) for i in (str(n) if n >= 0 else str(n)[1:])]
Note that this code above also checks if the original number is negative so it doesn't include the negative sign.
How to sum the first and last digit of the reverse integer?
can you explain what is *digit means?
please, could you explain the character before digits in print? the * it does not work for me
What if the the number was -12345678? How would you keep the -1?
@GetIt negative sign
can you make a video of the inverse ie obtaining the numbers and making then into a number
Bro pls tell how separate the odd and even number in digits in pythonn
Use the same technique as described in the video. However, instead of adding each digit you extract to a single list, check if the digit is even using digit % 2 == 0. If it is odd, this should be false, but if it is even, it should be true.
How can i do this in c programming
Check out the C code below. This works for any integer.
gist.github.com/pr28416/1ae389477455fdeb98216878a089c0d0
you saved me thanks!
🔥
num=1234589
l=[i for i in str(num)] the string method
Great tutorial but i need this in java :(
Java code is attached below. This shows the use of either Arrays or ArrayLists for accomplishing this:
gist.github.com/pr28416/eae736a9c27dc3263100c13d4a6bfbc3
Hope this helps.
@@pranavramesh1 Thank you so much.
It's not like 1024; without 0 its working fine :-)
The code will work for any positive integer (n ≥ 1), including numbers like 1024 containing a 0.
It's so hard...
Zoom& xplain bro