
![]() |
@wtf | |
*9 tips to improve your problem-solving skills in coding:* Understand the problem before coding Break problems into smaller parts Practice daily on platforms like LeetCode or HackerRank Learn common data structures and algorithms Draw diagrams to visualize logic Dry run your code with sample inputs Focus on optimizing time and space complexity Review solutions after solving a problem Don’t fear hard problems — struggle builds skill |
||
9
Replies
63
Views
1 Bookmarks
|
Page #: 1/2 |
![]() |
@wtf | 3 days |
Python Cheatsheet 1. Common Data Types int, float – numbers str – text list – ordered, changeable collection dict – key-value pairs tuple – like list, but unchangeable set – unique, unordered items 2. Essential Functions print() – display output type() – check data type len() – count items range() – generate numbers input() – take user input 3. String Methods .upper(), .lower() – change case .strip() – remove whitespace .replace() – swap text .split() – break into list 4. List Methods append() – add item pop() – remove item sort() – sort list [1:4] – slicing (get part of list) 5. Dictionary Basics Access: mydict['key'] Safe access: mydict.get('key') Add/Update: mydict['new'] = value 6. Control Flow if / elif / else – conditions for – loop over items while – loop with condition break / continue – control loop 7. Functions def – define a function return – return a value lambda – short anonymous function 8. Useful Built-in Modules math – sqrt, pi, round random – random numbers, choices datetime – current date/time os – system & file handling 9. Popular Libraries for Data Work NumPy – numerical operations Pandas – dataframes and analysis Matplotlib |
||
![]() |
@wtf | 1 day 16 hours |
*Variables & Data Types in Python* What are Variables? Variables are used to store data so you can refer to it and manipulate it later in your code. You don’t need to declare the type of variable explicitly in Python — it figures it out based on the value you assign. Example: x = 10 name = Alice price = 19.99 is_active = True Data Types in Python int – Integer numbers Example: x = 5 float – Decimal numbers Example: pi = 3.14 str – String or text Example: name = John bool – Boolean values (True or False) Example: is_logged_in = False list – An ordered, changeable collection Example: fruits = [apple, banana, cherry] tuple – An ordered, unchangeable collection Example: coordinates = (10, 20) set – An unordered collection of unique items Example: unique_ids = 1, 2, 3 dict – A collection of key-value pairs Example: person = name: Alice, age: 25 |
||
![]() |
@wtf | 1 day 16 hours |
*Control Flow (if, elif, else) in Python* What is Control Flow? Control flow allows your code to make decisions. You use if, elif, and else statements to run different blocks of code depending on conditions. Basic Structure: if condition: code runs if condition is True elif another_condition: code runs if the second condition is True else: code runs if none of the above are True Example: age = 20 if age 18: print(You are a minor.) elif age == 18: print(You just became an adult!) else: print(You are an adult.) Comparison Operators: == (equal to) != (not equal to) (less than) = (less than or equal to) = (greater than or equal to) Logical Operators: and – Both conditions must be True or – At least one condition must be True not – Reverses the result (True becomes False) Example with logical operators: age = 25 is_student = False if age 18 and not is_student: print(Eligible for the job.) |
||
![]() |
@wtf | 23 hours |
*_Let's go through important Python Topics Everyday starting with the first one today_* *Variables & Data Types in Python* What are Variables? Variables are used to store data so you can refer to it and manipulate it later in your code. You don’t need to declare the type of variable explicitly in Python — it figures it out based on the value you assign. Example: x = 10 name = Alice price = 19.99 is_active = True Data Types in Python int – Integer numbers Example: x = 5 float – Decimal numbers Example: pi = 3.14 str – String or text Example: name = John bool – Boolean values (True or False) Example: is_logged_in = False list – An ordered, changeable collection Example: fruits = [apple, banana, cherry] tuple – An ordered, unchangeable collection Example: coordinates = (10, 20) set – An unordered collection of unique items Example: unique_ids = 1, 2, 3 dict – A collection of key-value pairs Example: person = name: Alice, age: 25 |
||
![]() |
@wtf | 23 hours |
*Control Flow (if, elif, else) in Python* What is Control Flow? Control flow allows your code to make decisions. You use if, elif, and else statements to run different blocks of code depending on conditions. Basic Structure: if condition: code runs if condition is True elif another_condition: code runs if the second condition is True else: code runs if none of the above are True Example: age = 20 if age 18: print(You are a minor.) elif age == 18: print(You just became an adult!) else: print(You are an adult.) Comparison Operators: == (equal to) != (not equal to) (less than) = (less than or equal to) = (greater than or equal to) Logical Operators: and – Both conditions must be True or – At least one condition must be True not – Reverses the result (True becomes False) Example with logical operators: age = 25 is_student = False if age 18 and not is_student: print(Eligible for the job.) |
||
![]() |
@wtf | 23 hours |
*Loops in Python (for & while)* What are Loops? Loops let you repeat a block of code multiple times. They’re essential for tasks like iterating over data, automating repetitive steps, or checking conditions. 1. For Loop Used to iterate over a sequence like a list, string, or range. Example: fruits = [apple, banana, cherry] for fruit in fruits: print(fruit) You can also use range() to loop a specific number of times: for i in range(5): print(i) 2. While Loop Repeats as long as a condition is True. Example: count = 0 while count 3: print(Count is:, count) count += 1 Loop Control Statements: break – exits the loop completely continue – skips the current iteration and continues with the next pass – does nothing (used as a placeholder) Example: for i in range(5): if i == 3: break print(i) |
||
![]() |
@wtf | 23 hours |
*Dictionaries in Python* A dictionary is a collection of key-value pairs. Each key is unique and maps to a value. Dictionaries are unordered (until Python 3.7) and mutable, meaning you can change them. *Creating a Dictionary:* person = name: Alice, age: 25, city: New York *Accessing Values* : print(person[name]) Output: Alice print(person.get(age)) Output: 25 Using .get() is safer because it won’t crash if the key doesn’t exist. *Adding or Updating Items:* person[email] = alice@example.com Add new key person[age] = 26 Update value *Deleting Items:* del person[city] *Looping through a Dictionary:* for key, value in person.items(): print(key, :, value) *Why Use Dictionaries?* - Fast access via keys - Ideal for storing structured data (like a JSON object) - Very flexible in combining with loops and functions |
||
![]() |
@wtf | 23 hours |
*Powerful One-Liners in Python You Should Know!* 1. *Swap Two Numbers* n1, n2 = n2, n1 2. *Reverse a String* reversed_string = input_string[::-1] 3. *Factorial of a Number* fact = lambda n: [1, 0][n 1] or fact(n - 1) * n 4. *Find Prime Numbers (2 to 10)* primes = list(filter(lambda x: all(x % y != 0 for y in range(2, x)), range(2, 10))) 5. *Check if a String is Palindrome* palindrome = input_string == input_string[::-1] |
||


