Sorting using Functions

Поделиться
HTML-код
  • Опубликовано: 18 ноя 2024

Комментарии • 21

  • @rsathya2000
    @rsathya2000 3 года назад +35

    @Sudarshan iyengar, sir.. I'm not new to programming, but new to python! I find your classes interesting and simple to understand. But the best part is that my son (9 yrs old), is more interested in your course than I am :) He is finding it extremely simple and easy to understand and is playing around with Python using your course contents.. Thanks a lot for making the course so simple and easy for everyone to understand

  • @susmitamainde9017
    @susmitamainde9017 2 года назад +4

    Sir i am new in programming Thank you so much for making such easy to understand content.😊😊

  • @rohankhandelwal2021
    @rohankhandelwal2021 3 года назад +14

    Sir aap hi maths2 bhi padha do 🙏🏻

  • @avenumadhav3568
    @avenumadhav3568 3 года назад +2

    ascending order: 4:50
    min element in list: 6:05 6:37
    obvious sort: 7:08
    moral of the story: 9:30 10:05

  • @HimanshuSingh-db4dp
    @HimanshuSingh-db4dp 2 года назад +3

    The only thing i'm wondering about is the "mimimum' you wrote in line 1.

  • @shailxiitm
    @shailxiitm 3 года назад +7

    u r great sir, thanks
    how many time sudarshan sir will return l. hahaaa

    • @sudarshaniyengar8549
      @sudarshaniyengar8549 3 года назад +3

      that is like saying thank you... for the lack of a better phrase :) :) :)

    • @shailxiitm
      @shailxiitm 3 года назад

      @@sudarshaniyengar8549 yes sir

  • @SACHINKUMAR-ql6fu
    @SACHINKUMAR-ql6fu 2 месяца назад

    We can just write the code in this way also
    def sort_list(l):
    x=[]
    l.sort()
    x=l.copy()
    l.clear()
    return x
    it also works fine😅

  • @umarulf
    @umarulf 2 дня назад

  • @shreyapal6111
    @shreyapal6111 3 года назад +2

    I noticed that you usually use 'for i in range(len(l))' instead of 'for i in l'.
    Is there any benefit of using the former over the latter?

    • @sayanghosh6996
      @sayanghosh6996 3 года назад +3

      if we dont plan to change the value of the elements in that for loop, then for-each (for i in l) is the better way to go. But if we want to change elements, i = .... wont really do anything in a for-each loop, there we need a C-style for loop and do l[i] = ...
      trying executing this code:
      l = [1,2,3]
      for i in l:
      print(i, end=' ')
      i = i + 10
      print(i)
      print(l)
      due to the prints inside the forloop it seems that the value changed, but it only changes the value of 'i' and doesn't touch the list itself. This can be seen in the last print (outside the loop) that still prints [1,2,3].
      So if we are finding the minimum value in a list we can use for i in l. (or better can just use min(l))
      If we are sorting the list using its indexes (not like the obvious sort in this lecture) then we need for i in range(len(l))
      bottomline, use foreach if you dont wish to change the list in that forloop
      If you are asking about time complexity (efficiency of the program) then they are almost the same, but the for i in range(len(l)) is slightttttly faster.

    • @shreyapal6111
      @shreyapal6111 3 года назад +2

      ​@@sayanghosh6996 Whoa, that's really interesting. I didn't know 'for i in range(len(l))' has a better time complexity.
      I just ran a few iterations of both variations and took down the time taken to execute. From what I got, it appears that they take _almost_ the same time, but 'for i in l' seems to be _slightly_ faster.
      But again, time complexity is not the same as time taken to execute. So, I might need to use larger samples to get a more accurate result.
      Hmm, now I'm tempted to look up the source code of range().

    • @sayanghosh6996
      @sayanghosh6996 3 года назад

      @@shreyapal6111 yeah they have the same time complexity i guess, but on my (not so rigourous) experiment i found range (len(l)) to run a few milliseconds faster.

    • @sudarshaniyengar8549
      @sudarshaniyengar8549 3 года назад +2

      I actually mention this very point in one of the videos coming ahead. Use your discretion and use the one that is easy for you (based on the context). In the current context both are equivalent.

    • @sudarshaniyengar8549
      @sudarshaniyengar8549 3 года назад +1

      @@shreyapal6111 I am not sure if there is any time complexity difference.