Python Forum
A function that checks if the list is sorted
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A function that checks if the list is sorted
#10
(Jun-16-2019, 05:52 PM)pooyan89 Wrote: I am not a very good programmer and had not a very good teacher! but at all cost I am trying to learn the base of programming... that is because I use this. It seems much more easier for me to write for example:
for i in range(len(a))
But you say it is a bad pattern for looping through a list ?

One of the reasons why for i in range(len(a)) is considered antipattern is that integer is usually used to access list elements by index. You don't need to do it in Python, as noisefloor pointed out you can iterate directly over list element without need to mess with access by indices. However, if you need integer then you should use enumerate.

If you want to learn fundamentals then you should not go for 'more easier for me to write' but 'what are the best practices' and 'why are they considered best practices'

One easy to understand and well presented material is Ned Batchelder Loop Like a Native
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: A function that checks if the list is sorted - by perfringo - Jun-16-2019, 08:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Sorted and display the Subclasses of BaseException Fernando_7obink 9 3,937 Feb-10-2021, 12:04 PM
Last Post: buran
  Functions returns content of dictionary as sorted list kyletremblay15 1 2,125 Nov-21-2019, 10:06 PM
Last Post: ichabod801
  help! function that checks if a file is a bed file, tips so i can code it myself lilyS 1 2,455 May-31-2019, 12:41 PM
Last Post: ichabod801
  defining a function to see if a list is sorted Siylo 14 7,287 Nov-29-2018, 05:25 PM
Last Post: wavic
  sorted list not displaying Crackity 6 5,246 Jul-18-2017, 12:50 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020