Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For loop + add something
#9
Python only pretends to have lists. In fact, internally, Python has integer indexed arrays, just the same as PHP.

Knowing a list is in fact an integer indexed array, the index beginning with zero, why not make use of that fact and the relationship of the length to the indexing? Simple and useful!

Because you can't do that with sets doesn't seem like much of a reason to abandon that approach with lists and plump for enumerate, when the indexing is already there.

I don't know how Python treats sets internally, but, probably, the string within the brackets is split on the commas, giving a list-like object, which can then be iterated over. Somehow Python has to access each element individually.

Also, for any given set, say, data = {7058, 7059, 7072, 7074, 7076}, I can immediately create a list: mylist = list(data)
Reply


Messages In This Thread
For loop + add something - by Matheus - Jun-23-2022, 07:34 PM
RE: For loop + add something - by Axel_Erfurt - Jun-23-2022, 07:43 PM
RE: For loop + add something - by Matheus - Jun-23-2022, 09:12 PM
RE: For loop + add something - by Matheus - Jun-23-2022, 09:06 PM
RE: For loop + add something - by BashBedlam - Jun-23-2022, 09:16 PM
RE: For loop + add something - by snippsat - Jun-23-2022, 09:19 PM
RE: For loop + add something - by Matheus - Jun-23-2022, 09:37 PM
RE: For loop + add something - by DeaD_EyE - Jun-23-2022, 10:18 PM
RE: For loop + add something - by Pedroski55 - Jun-23-2022, 11:04 PM
RE: For loop + add something - by snippsat - Jun-24-2022, 01:03 AM
RE: For loop + add something - by DeaD_EyE - Jun-24-2022, 08:26 AM

Forum Jump:

User Panel Messages

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