Python Forum
Improving the program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Improving the program
#4
I think this:

                for k in range (sar.index(j)+1, len(sar)):
                    #nuo to rasto elemento ištrina visus tokius pačius
                    #(pirmą palieka)
                    if k >= len(sar):
                        break
                    if sar[k] == i:
                        del sar[k]
Could be replaced with a replace, so to speak. Something like:

start = sar.index(j) + 1
sar = sar[:start] + sar[start:].replace(i, '')
Although I guess I'm assuming sar is a string. If it's a list, maybe:

start = sar.index(j) + 1
sar = sar[:start] + [x for x in sar[start:] if x != i]
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Improving the program - by sunhyunshine - May-13-2019, 04:50 PM
RE: Improving the program - by heiner55 - May-17-2019, 03:45 PM
RE: Improving the program - by Larz60+ - May-17-2019, 08:43 PM
RE: Improving the program - by ichabod801 - May-17-2019, 09:55 PM
RE: Improving the program - by nilamo - May-17-2019, 09:58 PM
RE: Improving the program - by perfringo - May-18-2019, 05:31 AM

Forum Jump:

User Panel Messages

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