If someone asked you to set a random seed in your code, what number would come to your mind? .........................Of course 42. 🤷♂️ 1. np.random.seed(42) #Python 2. Random rand = new Random(42); #Java 3. mt_srand(42); #PHP 4. srand(42); #C....................................everybody! But why?🤔 Turns out, it’s not a machine learning secret - it’s a sci-fi Easter egg. 🌌 The number 42 became famous from the classic novel “The Hitchhiker’s Guide to the Galaxy” by Douglas Adams (1979). In the story, a group of hyper-intelligent beings build a supercomputer named Deep Thought to find the Answer to the Ultimate Question of Life, the Universe, and Everything. After 7.5 million years of computation, Deep Thought finally responds: “The answer is 42.” …but no one actually knows what the question was 🤷♂️ So, every time we use np.random.seed(42), we’re not just fixing randomness we’re keeping a programmer tradition alive 😄 #Python #NumPy #MachineLearning #ProgrammingHumor #HitchhikersGuide #DeveloperLife
Why 42 is the random seed number in code
More Relevant Posts
-
🚀 LaNet-vi is back — now in Python! LaNet-vi (Large Network Visualization), originally by José Ignacio Alvarez-Hamelin & Mariano Beiró, is a fantastic tool for exploring large graphs. A few weeks ago, I wanted to visualize the evolution of the AS-level Internet graph, but the C++ build + deps made it challenging, so I ported it to Python. 🧠 What’s k-core decomposition (the heart of LaNet-vi)? It “peels” the network by iteratively removing nodes with degree < k, revealing nested k-shells. These shells form tiers, a natural hierarchy from the sparse periphery (low k) into increasingly dense cores (high k). LaNet-vi visualizes these tiers so you can see the Internet’s structural backbone at a glance. What’s new 🐍 Pure-Python reimplementation using networkx, matplotlib, and pandas ⚡ Modern dependency management with uv 📥 Broader input formats support 🧯 More robust error handling + structured logging 🔓 Open repo for issues & contributions — and a PyPI release Links GitHub: https://lnkd.in/dhT7ssT2 PyPI: https://lnkd.in/dgKnXB3i 💡 Demo: AS-level Internet graph rendered with CAIDA’s October 2025 AS-relationship dataset. If this is useful, please ⭐ the repo and open issues/PRs — feedback welcome! #Python #OpenSource #NetworkScience #Visualization #InternetTopology #NetworkX #Matplotlib
To view or add a comment, sign in
-
-
Python Sets Explained – Fast, Unique, and Powerful! # Definition: A Set in Python is an unordered collection of unique elements, used to store multiple items without duplicates. # Characteristics: - Unordered and unindexed - No duplicate elements - Mutable (add or remove items) - Elements must be immutable (int, string, tuple) - Supports union, intersection, and difference operations # Commonly Used Methods: add(), update(), remove(), discard(), pop(), clear(), union(), intersection(), difference(), symmetric_difference(), copy() # Common Functions: len(), max(), min(), sum(), sorted(), any(), all() # LeetCode Problems: 217 Contains Duplicate 771 Jewels and Stones 136 Single Number 268 Missing Number 575 Distribute Candies 41 First Missing Positive 1207 Unique Number of Occurrence # Summary: Sets are efficient for removing duplicates, performing set operations, and optimizing comparison logic. LogicWhile #Python #Sets #PythonProgramming #Coding #ProblemSolving #LearnPython #DataStructures #LeetCode #DSA #CodeNewbie #SoftwareEngineer #Developer #CodingJourney #PythonLearning #Programming #100DaysOfCode #TechCommunity #LogicBuilding #CodingPractice #StudyWithMe #TechEducation #PythonBasics #Algorithms #CodeDaily #CodingLife #LearningInPublic
To view or add a comment, sign in
-
🚀 Efficient Binary Array Sorting with Two Pointers in Python Today I tackled a classic problem: sorting an array of 0s and 1s so that all 0s come before all 1s — in-place and efficiently. 🔧 Approach: Used the two-pointer technique to swap misplaced 0s and 1s from both ends of the array. No extra space, just clean logic. 📌 Code Snippet: class Solution: def zerosandones(self, nums: list) -> None: first, second = 0, len(nums) - 1 while first < second: if nums[first] == 0: first += 1 elif nums[second] == 1: second -= 1 else: nums[first], nums[second] = nums[second], nums[first] first += 1 second -= 1 print(nums) # Example usage s = Solution() s.zerosandones([0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1]) ✅ Time Complexity: O(n) ✅ Space Complexity: O(1) 💡 This is a great warm-up for problems like the Dutch National Flag or partitioning arrays. Have you used two pointers in your recent coding challenges? Share your favorite use case below! 👇 #Python #Coding #LeetCode #ProblemSolving #TwoPointers #DataStructures #Algorithms #LinkedInLearning
To view or add a comment, sign in
-
🚀 Python 3.14 Just Broke Its Biggest Limitation! For 30+ years, Python had a secret bottleneck — the GIL (Global Interpreter Lock) — the reason why your “multi-threaded” Python code still ran on just one CPU core 😅 That changes today with Python 3.14 💥 Python now has a free-threaded build (aka no-GIL Python) — meaning: ✅ True parallel execution across multiple cores ✅ Massive performance boost for CPU-heavy workloads ✅ Same Python you love — just faster Here’s the crazy part 👇 ```python import threading def work(): x = 0 for _ in range(10_000_000): x += 1 threads = [threading.Thread(target=work) for _ in range(4)] for t in threads: t.start() for t in threads: t.join() ``` 🐍 Old Python: all threads fight for the GIL → 1 core used ⚡ Python 3.14 (no-GIL): all 4 cores blaze in parallel! This is the biggest performance leap since Python 3 itself — and it might finally silence the “Python is slow” crowd 😎 Would you switch to the no-GIL build or wait until libraries (NumPy, Pandas, etc.) catch up? #Python #Python314 #NoGIL #Performance #Developers #Programming #OpenSource #TechNews
To view or add a comment, sign in
-
While learning Rust, i found something odd about len(). In Python, len() is a global function. Return the length (the number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set). Fun fact: it raises OverflowError for lengths exceeding sys.maxsize. such as range(2 ** 100). Rust:len() is a method on types like String, Vec, etc, not a global function. For strings (String, &str): len() gives you bytes, not characters count. For actual character count, you’ll need .chars().count(). For collections (Vec, arrays, HashMap): len() counts elements, as expected. Also, Rust's len() always returns usize (unsigned integer), so no negative lengths or overflow errors like Python! Different philosophies, same three letters.... #rust #python #len #iced #dev
To view or add a comment, sign in
-
🚀 Just built the first version of my own programming language — JSC (Just a Simple Compiler)! Over the past few days, I’ve been experimenting with building a custom compiler and interpreter using Python. The idea is to have a simple, human-readable scripting language that ends statements with semicolons, uses var for declarations, render for output, and even supports a future AI helper command assist. Here’s a quick example: /-----------------------------------------------/ | | *c Just a Simple Compiler Example v1.1 | | var name = "Manvendra"; | var x = 5; | var y = 10; | | render "Hello, " + name + "!"; | var total = y - x; | render "Total = " + total; | /-----------------------------------------------/ Running this gives: /-----------------------/ | | Hello, Manvendra! | Total = 5 | /-----------------------/ I also added type-smart addition, comments, and planned AI-assisted syntax hints 👨💻 Still early, but it feels great seeing something I imagined actually run line by line like a real language. Will keep evolving it — maybe next step: loops, conditionals, and basic error handling! #Python #CompilerDesign #ProgrammingLanguage #DevProject #LearningInPublic #FrontendToSystems
To view or add a comment, sign in
-
-
Nesting three loops and translating that into a single list comprehension can be a little bit tricky. Today I tackled a fun Python challenge using list comprehensions, and I found it super interesting! I generated all combinations [i, j, k] within given ranges where the sum isn’t equal to a target value n. It really stretched my thinking about nested loops and concise Python syntax. Example output (for x=1, y=1, z=2, n=3): [[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 0], [1, 0, 1], [0, 1, 1]] If you’ve solved similar combinatorics or Python list comprehension problems, I’d love to hear your approach! #Python #Coding #LearningInPublic #100DaysOfCode #ProblemSolving #ListComprehension #BeginnerToBuilder
To view or add a comment, sign in
-
Practicing Python by building 3 small projects I’ve been focusing on core Python concepts by shipping tiny command-line apps. Nothing fancy, just real reps. 1) Number Guessing Game Computer picks a number 1–100 → you guess. Feedback after each try: Too high / Too low / Correct. Concepts: input handling, random, loops, guardrails. 2) Rock–Paper–Scissors Play vs the computer; r/p/s inputs, q to quit. Keeps track of wins/losses/ties with clear prompts. Concepts: branching, simple state, replay loop. 3) Python Trivia Quiz 5 random questions from a small in-memory set. Case-insensitive answers, instant feedback, final score /5. Concepts: dicts, random sampling, string ops. I’ll post the GitHub link in the comments. If you have ideas for the next small project. I’m all ears. #Python #LearningInPublic #DevOps #Automation #BeginnerProjects #BuildNotWatch
To view or add a comment, sign in
-
🔁 Understanding Recursion with the Call Stack (Python) Recursion is when a function calls itself. To really understand what happens, visualize the call stack. Example: def show(n): if n == 0: return print(n) show(n - 1) print("END") show(3) Output: 3 2 1 END END END Call stack walkthrough: - show(3): prints 3, calls show(2) → Stack: [show(3)] - show(2): prints 2, calls show(1) → Stack: [show(3), show(2)] - show(1): prints 1, calls show(0) → Stack: [show(3), show(2), show(1)] - show(0): base case → return. As the stack unwinds, each function resumes and prints "END". That’s why "END" appears three times. Use cases: tree traversal (DFS), sorting (QuickSort/MergeSort), backtracking, filesystem traversal. Key takeaway: Recursion is powerful — always include a base case. #Python #Recursion #CallStack #Programming #Tech
To view or add a comment, sign in
-
Day 53 of Python Problem-Solving – “Missing Number” Challenge! Today’s problem was about finding the missing number from a list of n distinct integers within the range [0, n]. Only one number is missing — and the task is to identify it efficiently. ✅ Approach & Learning I solved this in two ways: 🔹 1. Optimized Approach (O(n) Time | O(1) Space) Used the mathematical formula: Sum of first n natural numbers=n(n+1)2\text{Sum of first n natural numbers} = \frac{n(n+1)}{2}Sum of first n natural numbers=2n(n+1)Simply subtracting the actual sum of the list from the expected sum gives the missing number. 🔹 2. Brute Force Approach Sort the list Compare index with value to find mismatch This helped reinforce the contrast between brute force and optimized logic. 🧠 Key Takeaways ✔ Mathematical formulas can eliminate loops & improve performance ✔ Always think about time and space efficiency ✔ Sometimes the smartest solution is also the simplest one 📍 Code Available On GitHub: 🔗 https://lnkd.in/g2HA9WKb #Day53 #100DaysOfCode #Python #CodingJourney #ProblemSolving #LearningDaily #DataStructures #Algorithms #LeetCode #KeepCoding
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development