Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
type for sequences
#1
is there a common parent type for all sequence types that would make it simpler to test if some object is any sequence using isinstance() without having to construct a big list that varies between python2 and python3?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Well, I learned something just now:

import collections for x in (list(), dict(), tuple(), set()): print(isinstance(x, (collections.abc.Mapping, collections.abc.Set, collections.abc.Sequence)))
Reply
#3
python 3 for stullis:
>>> from collections import abc >>> for x in (list(), dict(), tuple(), set()): ... print(isinstance(x, (abc.Mapping, abc.Set, abc.Sequence))

Disregard,
Misread code
Reply
#4
from collections import abc all(isinstance(x, (abc.Mapping, abc.Set, abc.Sequence)) for x in (list(), dict(), tuple(), set(), str(), bytes(), bytearray(), frozenset()))
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  detect equal sequences in list flash77 17 7,168 Oct-28-2022, 06:38 AM
Last Post: flash77
  needleman wunsch algorithm for two sequences of different length johnny_sav1992 0 2,812 Jul-27-2020, 05:45 PM
Last Post: johnny_sav1992
  Type hinting - return type based on parameter micseydel 2 3,777 Jan-14-2020, 01:20 AM
Last Post: micseydel
  help for escape sequences NewPi 1 3,070 Dec-11-2019, 11:22 PM
Last Post: ichabod801
  copying parts of mutable sequences Skaperen 1 3,372 Dec-02-2019, 10:34 AM
Last Post: Gribouillis
  Convert weekly sequences to date and time. SinPy 0 2,296 Nov-23-2019, 05:20 PM
Last Post: SinPy
  Escape sequences display in python Uchikago 1 3,676 Jun-27-2019, 03:25 PM
Last Post: Gribouillis
  comparing strings (or sequences) Skaperen 5 6,597 Jan-25-2017, 10:30 AM
Last Post: Skaperen

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.