6 ms·
In 25 years you’ve never once created a list with more than one type of object in it?
by joshmaker 4y ago
In 25 years you’ve never once created a list with more than one type of object in it?
- gautamdivgi 4y agoI’ll second that. I’ve been doing python for a while and haven’t used the mixed type list. I’ve actively avoided doing something like that. The situation doesn’t come up often.
- cjohnson318 4y agoMaybe a list with ThingObject or None, but my lists are usually homogenous.
- mrfox321 4y agothats just homogenous Sequence[Optional[T]], though.
- bombolo 4y agowell list[int|str] is as well
- cjohnson318 4y agoYeah, that's a better way of putting it :) 90% of the time, I'm something like Sequence[T], but I'm sure I've used Sequence[Optional[T]] a couple of times. I mean, I could drive donuts in the Piggly Wiggly parking lot at 3a, I just don't, and the same for heterogenous lists.
- agumonkey 4y agoAnd everything is a subtype of Any. The usual 'static typing' of dynlangs.
- mangecoeur 4y agoI have also been using python a long time and i honestly can’t remember a time i used mixed type list.
- ris 4y agoNever have to handle/forward function calls with arbitrary arguments? What do you think *args is?
- mangecoeur 4y agoa tuple
- querez 4y agoIn my code this comes up often, e.g. when I use tuples instead of namedtuple or a dataclass.
- bastawhiz 4y agoTuples aren't lists though. Tuples are really just structs with indexes instead of names.
- froggit 4y agoI use mixed lists all the time to store shit, but I'm also a total python newb that really doesn't know better.
- throwaway894345 4y agoI mean, it depends on what you mean by “type”. A list of some Protocol type (what other languages call “interfaces”) is still a homogenous list even though the concrete types are heterogeneous. This is almost always what you want when you’re thinking of “a heterogeneous list”.
- bombolo 4y agoIt's not unheard of to have unions and a couple of if isinstance. In fact it's why in python they even have the | operator between types nowadays.
- terhechte 4y agoSame here. If I needed that I might use a tuple.
- amelius 4y agoAnd then it crashes when you convert it to JSON.
- UncleEntity 4y agoI just use an extension wrapper around boost::property_tree for my json (and xml) needs. Way faster than the built in json support and does automagic type conversion so I don’t have to worry about it. Now, I’m not running at Web Scale™ but pure python was slow enough to be annoying.
- eddsh1994 4y agoHuh, thinking about it I haven't in 9 years either