Python 3 Tutorial - Split Integer Into Digits

Поділитися
Вставка
  • Опубліковано 6 лис 2024

КОМЕНТАРІ • 30

  • @abhaypramod2404
    @abhaypramod2404 2 місяці тому

    Helped me in ai practical exam. Thanks :D

  • @jumabozorov2392
    @jumabozorov2392 Рік тому

    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.

  • @Jimmy-zw9ve
    @Jimmy-zw9ve 4 роки тому +4

    thx dude, you helped me solve the Leetcode question #1281

  • @delvstudio
    @delvstudio Рік тому

    brooo thank you so much, i had trouble understanding this but you have helped me alot! Thanks!

  • @the_bruised_bard
    @the_bruised_bard Рік тому

    Hey man! When I use the same logic, only the first element of the list is getting displayed. Please help me..

  • @chrisnorthall8317
    @chrisnorthall8317 Рік тому +2

    or
    my_int = 123456789
    my_list = [int(x) for x in str(my_int)]
    print(my_list)

  • @farhanrahman7664
    @farhanrahman7664 Рік тому

    so mod in python is the DIV library routine in pseudocode?

  • @jessicawade4775
    @jessicawade4775 4 роки тому +3

    What's the simpler, less mathmatical way?

    • @pranavramesh1
      @pranavramesh1  3 роки тому +3

      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.

  • @azreenamirah6485
    @azreenamirah6485 Рік тому

    How to sum the first and last digit of the reverse integer?

  • @pranjalshukla8096
    @pranjalshukla8096 3 роки тому

    can you explain what is *digit means?

  • @aminraeisi1043
    @aminraeisi1043 2 роки тому

    please, could you explain the character before digits in print? the * it does not work for me

  • @javonnii436
    @javonnii436 4 роки тому +1

    What if the the number was -12345678? How would you keep the -1?

  • @tejasbalamukesh8342
    @tejasbalamukesh8342 2 роки тому

    can you make a video of the inverse ie obtaining the numbers and making then into a number

  • @balajisubramanian6481
    @balajisubramanian6481 3 роки тому +1

    Bro pls tell how separate the odd and even number in digits in pythonn

    • @pranavramesh1
      @pranavramesh1  3 роки тому +3

      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.

  • @denielkailabine6614
    @denielkailabine6614 2 роки тому

    How can i do this in c programming

    • @pranavramesh1
      @pranavramesh1  2 роки тому

      Check out the C code below. This works for any integer.
      gist.github.com/pr28416/1ae389477455fdeb98216878a089c0d0

  • @onionM3h45
    @onionM3h45 3 роки тому

    you saved me thanks!

  • @mohinkumar4255
    @mohinkumar4255 3 роки тому +1

    🔥

  • @pythoneer370
    @pythoneer370 2 роки тому

    num=1234589
    l=[i for i in str(num)] the string method

  • @Youngballer739
    @Youngballer739 3 роки тому +1

    Great tutorial but i need this in java :(

    • @pranavramesh1
      @pranavramesh1  3 роки тому

      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.

    • @Youngballer739
      @Youngballer739 3 роки тому

      @@pranavramesh1 Thank you so much.

  • @easinwebpro
    @easinwebpro 3 роки тому

    It's not like 1024; without 0 its working fine :-)

    • @pranavramesh1
      @pranavramesh1  3 роки тому

      The code will work for any positive integer (n ≥ 1), including numbers like 1024 containing a 0.

  • @donpilarsuarezgudino5160
    @donpilarsuarezgudino5160 3 роки тому

    It's so hard...

  • @rayeesahmed3893
    @rayeesahmed3893 3 роки тому

    Zoom& xplain bro