Python Forum
[Basic] Never use "for i in range(len(sequence)):"
Thread Rating:
  • 4 Vote(s) - 3.25 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Basic] Never use "for i in range(len(sequence)):"
#4
(Sep-18-2017, 11:38 AM)metulburr Wrote: maybe add a zip in a for loop example as questioned here
Quote:for i in correct:
#how could i compare here the two array without writing it in the C way?
for item, check in zip(received, correct):
    if item == check:
        coincident += 1
 

 Wouldn't it be better to avoid an intermediate variable or zipping, and instead just do set arithmetic?
coincident = len(set(received) & set(correct))
Unless one or both of those are a generator/stream to something that might not all fit into memory, I suppose.


Messages In This Thread
RE: Never use "for i in range(len(sequence)):" - by nilamo - Sep-26-2017, 09:11 PM

Forum Jump:

User Panel Messages

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