Posts: 4,646
Threads: 1,493
Joined: Sep 2016
how to test if something is a sequence (as opposed to merely a list)?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,786
Threads: 76
Joined: Jan 2018
Jun-10-2024, 06:44 AM
(This post was last modified: Jun-10-2024, 06:45 AM by Gribouillis.)
Use perhaps
collections.abc.Iterable
isinstance(obj, Iterable)
Documentation Wrote:The only reliable way to determine whether an object is iterable is to call iter(obj)
« We can solve any problem by introducing an extra level of indirection »
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
does that mean i can't use an int to index a mapping? or is an int mutable (i don't think so)?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
Jul-11-2024, 12:03 AM
(This post was last modified: Jul-11-2024, 12:03 AM by Skaperen.)
(Jun-11-2024, 05:05 AM)perfringo Wrote: List is sequence so there is no opposition.
my goal is to test if
foo is a sequence even if it is not a list. maybe it is a string. maybe it is a set. is it a sequence?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
(Jun-10-2024, 06:44 AM)Gribouillis Wrote: Use perhaps collections.abc.Iterable
isinstance(obj, Iterable)
Documentation Wrote:The only reliable way to determine whether an object is iterable is to call iter(obj)
what will that do if
obj is a set? my thinking of a set is that it is iterable but it is not a sequence.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.