Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

set-comprehension

Python Set Comprehension

January 10, 2023 by Tarik

primes = {x for x in range(2, 101) if all(x%y for y in range(2, min(x, 11)))} I simplified the test a bit – if all(x%y instead of if not any(not x%y I also limited y’s range; there is no point in testing for divisors > sqrt(x). So max(x) == 100 implies max(y) == 10. For … Read more

Categories python Tags python, set, set-comprehension Leave a comment

Why is there no tuple comprehension in Python?

September 15, 2022 by Tarik

You can use a generator expression: tuple(i for i in (1, 2, 3)) but parentheses were already taken for … generator expressions.

Categories python Tags dictionary-comprehension, list-comprehension, python, set-comprehension, tuples Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa