Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8951847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:45:13+00:00 2026-06-15T13:45:13+00:00

Given a list, I wanted to check if all the elements in that list

  • 0

Given a list, I wanted to check if all the elements in that list are divisible by some given integer or not. Based on that, i have to return a boolean value.

l=[10,30,40,20]

For example – all the elements of this list are divisible by 5. Then, I would return True.
For 6, I would have returned False.

One approach I could think of is to generate an array consisting off boolean values and then AND them.

blist=[x%5==0 for x in l]
# [False, False, False, False]
# AND THE ELEMENTS

But this approach kind of feels bad. Can anyone suggest a more simple pythonic way out of this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:45:14+00:00Added an answer on June 15, 2026 at 1:45 pm

    First of all, you want modulo division (%) as you want to see if it evenly divides by 5, so you are checking for a remainder, not the result of division.

    You can use the all() builtin (which does what it says on the tin), but you don’t need to generate a list, instead use a generator expression:

    all(x%5 == 0 for x in l)
    

    This has the advantage of being lazy, so as soon as a value isn’t divisible it will return, saving computation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that I wanted to list the names and prices of venues within an
I have a widget that fills a list with some downloaded information, which includes
Given a list of elements like so: int[] ia = new int[] { -4,
I wanted to make a linked list class ListList that inherits from a class
My application has got several pages. On some pages I have given a back
I have an object that looks like this. List<List<string>> MyData; The inner List<string> can
I would like to get a list of all subclasses of a given class
Given a list of e.g. two elements l = [1,0] I need to create
I created a small implementation of the container list that performs certain functions based
I have a huge list of video files from a webcam that have that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.