Python Forum
what's homogeneus items defined by list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what's homogeneus items defined by list
#6
If you have a list containing a heterogeneous sequence of items, then it means different positions in that list are going to have to be treated differently. Your code will then be littered with lots of checks on the index to handle those different cases. There are two problems with that:

1. It's hard to read. You end up wondering why those indices are what they are. I suppose you could have variables to give names to them, but you can't get away from the conditional checks. You'd be better off using a class or named tuple to model the structure.

2. It really won't scale very well. Today you might only have 5 items in that list, but what happens tomorrow when you have a 100 or more? That code is just going to be painful to maintain.
Reply


Messages In This Thread
RE: what's homogeneus items defined by list - by ndc85430 - Jun-25-2020, 11:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  variable not defined inside a list comprehension Phidias618 1 2,023 May-13-2023, 09:05 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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