Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
What type-hint contains both list and tuple?

I have a function that can accept as input any variable that can be indexed, such as a list or a tuple. How do I indicate this in the type-hint of the function?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Your method is accepting a sequence, so use typing.Sequence. That's a generic, so you can specify what type of object(s) the sequence must contain:

from typing import Sequence

def foo(bar: Sequence[int]):
    # bar is a sequence of integers

Quoting the Python glossary:

An iterable which supports efficient element access using integer indices via the __getitem__() special method and defines a __len__() method that returns the length of the sequence. Some built-in sequence types are list, str, tuple, and bytes.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!