🐍 Python Study Notes Week 3 (Day 3–6) 📘 Day 3: Python Modules and Libraries 🔹 What is a Module? A module is a file containing Python code (functions, classes, variables) that can be reused in other programs. 🔹 What is a Library? A library is a collection of modules that provide specific functionality, like math operations or random number generation. 📐 math Module Used for mathematical operations. import math print(math.sqrt(1000)) # Square root of 1000 print(math.pi) # Value of π (pi) You can rename the module: import math as m print(m.pow(2, 6)) # 2 raised to the power of 6 🎲 random Module Used to generate random values. import random print(random.random()) # Random float between 0 and 1 print(random.randint(100, 150)) # Random integer between 100 and 150 colors = ["red", "blue", "black", "yellow", "green"] print(random.choice(colors)) # Randomly picks one item random.shuffle(colors) # Shuffles the list print(colors) 📘 Day 4: Working with Dates and Time 🔹 datetime Module Used to work with dates and times. import datetime from datetime import datetime, date, time, timedelta current_datetime = datetime.now() print(current_datetime) # Current date and time print(current_datetime.year) # Year print(current_datetime.month) # Month print(current_datetime.day) # Day 📌 Other Components date() – Represents a calendar date. time() – Represents time (hour, minute, second). datetime() – Combines date and time. timedelta() – Represents a duration (difference between two dates/times). 📘 Day 5: Problem Solving with Dictionaries 🔹 What is a Dictionary? A dictionary is a collection of key-value pairs. It helps store and retrieve data efficiently. 🧩 Problem: Find the Most Repetitive Element L1 = [1, 2, 2, 3, 2, 3, 4, 5] counts = {} for item in L1: if item in counts: counts[item] += 1 else: counts[item] = 1 print(counts) temp = 0 most_repetitive_elements = None for k, v in counts.items(): print(f"item : {k}, value : {v}, temp = {temp}") if v > temp: temp = v most_repetitive_elements = k print("most repetitiveelement is : ",most_repetitive_elements) 📘 Day 6: Problem Solving Without Dictionary 🧩 Same Problem, Different Approach l1 = [1, 2, 2, 3, 2, 3, 4, 5] most_repetitive_elements = None max_count = 0 for item in l1: count = l1.count(item) print(f"Item : {item}, count : {count}") if count > max_count: max_count = count most_repetitive_elements = item print(f"The most repetitive element is : {most_repetitive_elements} and count is : {max_count}") #python #DataEngineer #AzureDataEngineer #DataAnalytics
"Python Study Notes: Modules, Dates, Dictionaries, Problem Solving"
More Relevant Posts
-
Python Loops! 👀 Loops helps us avoid repetition in our code and consolidate large data into clean, short and readable code. 💭 Why Loops Matter? Loops allow programs to repeat actions efficiently without writing the same code multiple times. In my Jupyter Notebook, I explored both major types of loops: 🔹 for loops: perfect for iterating through sequences, lists, and ranges 🔹 while loops: great when repetition depends on a condition rather than a count 🔹 break / continue: for controlling flow precisely 🔹 range(start, stop, step): mastering how iteration sequences work 🔹 Nested loops: loops inside loops for multi-dimensional logic 🔹 Avoiding infinite loops: understanding when and how to end repetition safely 😊Good News: My Jupyter Notebook for Python Loops Is Up On My Github! Make sure to check it out and try to do mini projects for python loops that i made there! Good Luck Python Beginners! 😊What Is Coming Next?: Python Functions In detail for Beginners like me! --------------------------- ☺️ Here are Python (Beginner to Intermediate) GitHub Repos for you: 📁Python Variables: https://lnkd.in/e9rjz-_D 📁Python Operators: https://lnkd.in/e6hzgHSn 📁Python Conditionals: https://lnkd.in/egQNGZBF 📁Python Loops: https://lnkd.in/eezUg_-y ------------------------- ⚡ Follow my learning journey: 📎 GitHub: https://lnkd.in/ehu8wX85 🔗GitLab: https://lnkd.in/eiiQP2gw 💬 Feedback: I’d love your thoughts and tips! 🤝 Collab: If you’re also exploring Python, DM me! Let’s grow together! -------------------------- #pythonconditionals #ifelifelseinpython #ternaryconditionals #nestedconditionals #conditionalswithoperators #pythonbasicknowledge #pythonbasicconcepts #pythonforbeginners #pythonprogramming #pythonfordatascience #pythonforaiml
To view or add a comment, sign in
-
-
💡 #Python Lists #Cheatsheet: Essential Operations This lesson provides a quick reference for common Python list operations. Lists are ordered, mutable collections of items, and mastering their use is fundamental for Python programming. This cheatsheet covers creation, access, modification, and utility methods. # 1. List #Creation my_list = [1, "hello", 3.14, True] empty_list = [] numbers = list(range(5)) # [0, 1, 2, 3, 4] # 2. #Accessing Elements (Indexing & Slicing) first_element = my_list[0] # 1 last_element = my_list[-1] # True sub_list = my_list[1:3] # ["hello", 3.14] copy_all = my_list[:] # [1, "hello", 3.14, True] # 3. #Modifying Elements my_list[1] = "world" # my_list is now [1, "world", 3.14, True] # 4. #Adding Elements my_list.append(False) # [1, "world", 3.14, True, False] my_list.insert(1, "new item") # [1, "new item", "world", 3.14, True, False] another_list = [5, 6] my_list.extend(another_list) # [1, "new item", "world", 3.14, True, False, 5, 6] # 5. #Removing Elements removed_value = my_list.pop() # Removes and returns last item (6) removed_at_index = my_list.pop(1) # Removes and returns "new item" my_list.remove("world") # Removes the first occurrence of "world" del my_list[0] # Deletes item at index 0 (1) my_list.clear() # Removes all items, list becomes [] #Re-create for other examples numbers = [3, 1, 4, 1, 5, 9, 2] # 6. #List #Information list_length = len(numbers) # 7 count_ones = numbers.count(1) # 2 index_of_five = numbers.index(5) # 4 (first occurrence) is_present = 9 in numbers # True is_not_present = 10 not in numbers # True # 7. #Sorting numbers_sorted_asc = sorted(numbers) # Returns new list: [1, 1, 2, 3, 4, 5, 9] numbers.sort(reverse=True) # Sorts in-place: [9, 5, 4, 3, 2, 1, 1] # 8. #Reversing numbers.reverse() # Reverses in-place: [1, 1, 2, 3, 4, 5, 9] # 9. #Iteration for item in numbers: # print(item) pass # Placeholder for loop body # 10. List #Comprehensions (Concise creation/transformation) squares = [x**2 for x in range(5)] # [0, 1, 4, 9, 16] even_numbers = [x for x in numbers if x % 2 == 0] # [2, 4] #Code #explanation: This script demonstrates fundamental list operations in Python. It covers creating lists, accessing elements using indexing and slicing, modifying existing elements, adding new items with append(), insert(), and extend(), and removing items using pop(), remove(), del, and clear(). It also shows how to get list information like length (len()), item counts (count()), and indices (index()), check for item existence (in), sort (sort(), sorted()), reverse (reverse()), and iterate through lists. Finally, it illustrates list comprehensions for concise list generation and filtering. #Python #Lists #DataStructures #Programming #Cheatsheet
To view or add a comment, sign in
-
📒 #LearningLog: Python's Arbitrary Arguments Continuing my Python journey on DataCamp's "Intermediate Python for Developers" course. Today's module was a deep dive into Arbitrary Arguments (*args and **kwargs), and it really clicked! Here are my key takeaways: 🔹 What are Arbitrary Arguments? They are a way to pass a variable number of arguments to a function, making the function much more flexible. 🔹 *args (Arbitrary Positional Arguments) This syntax allows a function to accept any number of positional arguments, and Python bundles them into a single tuple. 🔹 **kwargs (Arbitrary Keyword Arguments) This syntax allows a function to accept any number of keyword arguments (like name="John"). Python bundles them into a dictionary. 🔹 Practical Application The key realization was how to use the **kwargs dictionary. To perform calculations (like an average), you must explicitly use the ".values()" method (e.g., sum(kwargs.values()) / len(kwargs.values())). Similarly, ".keys()" can be used to access the names of the arguments passed. This concept unlocks so much flexibility for creating robust functions. On to the next module! #Python #DataCamp #LearningJournal
To view or add a comment, sign in
-
Once you've downloaded free-threading (GIL-free) Python, you can see immediate improvements in your run times. Take the following small snippet of code. #test.py import threading, math, time def cpu_heavy(): # Pure CPU loop: each thread fights for the GIL in normal Python for _ in range(50_000_000): math.sqrt(12345) threads = [threading.Thread(target=cpu_heavy) for _ in range(4)] t0 = time.time() for t in threads: t.start() for t in threads: t.join() print(f"Time: {time.time() - t0:.2f}s") Let's run it with regular, then GIL-free Python c:\> python test.py Time: 8.63s c:\> python3.14t test.py Time: 2.09s It's not a panacea, but if you want to find out how to download GIL-free Python and start using it for immediate results, check out the article I wrote about it on the Towards Data Science blog. You can read it for free by using the link below. https://lnkd.in/e4TTMphY
To view or add a comment, sign in
-
We all love Python for its readability and ease of use, but what happens when you hit a computational bottleneck? While Python is fantastic for many tasks, it can struggle with time-critical operations. But what if you could get the best of both worlds? I've written a comprehensive guide on how to supercharge your Python code by integrating C for the heavy lifting. In my latest article on the Towards Data Science platform, I outline 3 different ways of offloading performance critical sections of Python code to C, resulting in performance boosts of up to **150x**. These techniques could be game-changing for anyone working on data processing, scientific computing, or any application where speed is paramount. Dive in now to learn how to combine the simplicity of Python with the raw power of C. Read the full guide for free using the link below https://lnkd.in/evmT7xyM
To view or add a comment, sign in
-
Hello Connections 👋 🐍🚀 Learning Update: Python Nested Lists & Matrix Problems.✅ 🔹Today, I learned about Nested Lists and solved Matrix-based Problems in Python. 💡Key Concepts and Their Definitions 🌟1. List in Python 🔹A list is an ordered, mutable collection of elements enclosed within square brackets [ ]. 🔹Lists can store multiple data types such as integers, strings, or even other lists. ✿Example: my_list = [1, 2, 3, 4] 🌟2. Nested List 🔹A nested list is a list that contains other lists as elements. It is used to represent multi-dimensional data, such as matrices (2D arrays). ✿Example: matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] 🌟3. Matrix 🔹A matrix is a rectangular arrangement of numbers in rows and columns. 🔹In Python, matrices are commonly represented using nested lists, where each inner list corresponds to a row. ✿Example: Matrix with 3 rows and 3 columns: 1 2 3 4 5 6 7 8 9 🌟4. Accessing Elements in a Matrix Elements can be accessed using two indices – one for the row and one for the column. ✿ Example: print(matrix[1][2]) ✨This session enhanced the understanding of multi-dimensional data structures in Python. 🌸Thanks to 10000 Coders for this wonderful learning experience!🙌 #ManojKumarReddyParlapalliSir #Python #NestedLists #Matrix #10000Coders #LearningJourney #ProblemSolving #CodingSkills #PythonProgramming
To view or add a comment, sign in
-
🐍 Learning Update: Python Nested Lists & Matrix Problems Today, I learned about Nested Lists and solved Matrix-based Problems in Python under the guidance of Manoj Kumar Reddy Parlapalli at 10000 Coders. This session helped in understanding how to represent and manipulate 2D data structures (matrices) using nested lists, which are widely used in real-world applications like data analysis, image processing, and mathematical computations. 💡 Key Concepts and Their Definitions 🔹 1. List in Python A list is an ordered, mutable collection of elements enclosed within square brackets [ ]. Lists can store multiple data types such as integers, strings, or even other lists. Example: my_list = [1, 2, 3, 4] 🔹 2. Nested List A nested list is a list that contains other lists as elements. It is used to represent multi-dimensional data, such as matrices (2D arrays). Example: matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] 🔹 3. Matrix A matrix is a rectangular arrangement of numbers in rows and columns. In Python, matrices are commonly represented using nested lists, where each inner list corresponds to a row. Example: Matrix with 3 rows and 3 columns: 1 2 3 4 5 6 7 8 9 🔹 4. Accessing Elements in a Matrix Elements can be accessed using two indices – one for the row and one for the column. Example: print(matrix[1][2]) # Output: 6 Conclusion This session enhanced the understanding of multi-dimensional data structures in Python and provided the foundation for more advanced concepts like NumPy arrays and data manipulation in the future. #Python #NestedLists #Matrix #10000Coders #LearningJourney #ManojKumarReddyParrapalli #ProblemSolving #CodingSkills #PythonProgramming Manoj Kumar Reddy Parlapalli 10000 Coders
To view or add a comment, sign in
-
🚀 Exploring File Handling in Python 🐍 Today, I explored one of the most fundamental yet powerful concepts in Python — File Handling. I practiced reading, writing, appending, and combining these operations using different file modes like: r → Read w → Write (overwrites existing file) a → Append (adds content to the end) r+ → Read and Write w+ → Write and Read (overwrites file) a+ → Append and Read (adds new data and allows reading) x → Create a new file (fails if file already exists) 💡 Key Takeaways: Each file mode behaves differently — some overwrite, others preserve data. The file cursor (seek() and tell()) plays a crucial role in controlling where data is read or written. a+ keeps old data and adds new content, while w+ clears old data and starts fresh. The x mode safely creates a new file and helps prevent overwriting. 📚 This experiment gave me a clear understanding of how file operations work in real-world applications — an essential skill for any Python developer. 10000 Coders Ajay Babu Sappa #Python #FileHandling #CodingJourney #LearningEveryday #DataScience #PythonProgramming
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