Community chat: https://t.me/hamster_kombat_chat_2
Twitter: x.com/hamster_kombat
YouTube: https://www.youtube.com/@HamsterKombat_Official
Bot: https://t.me/hamster_kombat_bot
Game: https://t.me/hamster_kombat_bot/
Last updated 3 months, 1 week ago
Your easy, fun crypto trading app for buying and trading any crypto on the market
Last updated 3 months ago
Turn your endless taps into a financial tool.
Join @tapswap_bot
Collaboration - @taping_Guru
Last updated 3 days, 5 hours ago
PyTip for the day:Use the "enumerate" function to iterate over a sequence and get the index of each element.
Sometimes when you're iterating over a list or other sequence in Python, you need to keep track of the index of the current element. One way to do this is to use a counter variable and increment it on each iteration, but this can be tedious and error-prone.
A better way to get the index of each element is to use the built-in "enumerate" function. The "enumerate" function takes an iterable (such as a list or tuple) as its argument and returns a sequence of (index, value) tuples, where "index" is the index of the current element and "value" is the value of the current element. Here's an example:
```
Iterate over a list of strings and print each string with its index
strings = ['apple', 'banana', 'cherry', 'date']
for i, s in enumerate(strings):
print(f"{i}: {s}")
```
In this example, we use the "enumerate" function to iterate over a list of strings. On each iteration, the "enumerate" function returns a tuple containing the index of the current string and the string itself. We use tuple unpacking to assign these values to the variables "i" and "s", and then print out the index and string on a separate line.
The output of this code would be:
```
apple
1: banana
2: cherry
3: date
```
Using the "enumerate" function can make your code more concise and easier to read, especially when you need to keep track of the index of each element in a sequence.
We are on Discord. Join us by clicking this link https://discord.gg/EPhnZDbS5T
Discord
Join the Python, ML & DataScience Discord Server!
Python Programmers Club is friendly community to learn Python programming from beginners to advanced. JoinUs & know more | 321 members
PyTip for the day: When working with lists in Python, consider using list comprehensions instead of for loops to perform operations on the list elements. List comprehensions are more concise, readable, and often faster than using traditional for loops.
For example, instead of using a for loop to create a new list that contains the squared values of the elements in an existing list, you can use a list comprehension like this:
numbers = 1, 2, 3, 4, 5
squarednumbers = [num * 2 for num in numbers]
This will create a new list squared*numbers containing the squared values of the elements in numbers.
Practice Code: 053
Task:
You have to create a program where a list of numbers is given and a number of rotation is given. Now you to bring last number of list in front and swift each number to the right. Do this till the given number of rotation.
Sample :-
input - [1,2,3,4] , 2
output - [4,1,2,3] -> [3,4,1,2]
Good luck!
««« Click here for solution »»»?Ready to take this challenge? ?
#python #practiceCode #samples #interviewQuestions #numbers #algorithm
Practice Code: 052
You have to create a program where you have to create a dictionary with key (1 to n) and value be square of the key.
Sample Run:-
input - 5
output - {1:1 , 2:4 , 3:9 , 4:16 , 5:25}
Good luck!
««« Click here for solution »»»?Ready to take this challenge? ?
#python #practiceCode #samples #interviewQuestions #numbers #algorithm
Practice Code: 051
Write a program to return the sum of a series of sequential numbers. The sequence can be
```
a. 1,2,3,4,5.......n
b. 1,3,5,7,9,11,.....n
c. 2,4,6,8,10,12.....n
d. 35,42,49,56,63....n
```
Note: Do not use a loop to add the numbers, if that is what your idea is, not use a sum() or similar function to add them.Write an algorithm that optimally finds the sum total.
««« Click here for solution »»»?Ready to take this challenge? ?
#python #practiceCode #samples #interviewQuestions #numbers #algorithm
#PracticeCode: 0050
? FORWARD IF YOU LIKE IT ?
Task:
You have to create a program where you have to create a list of first 5 and last 5 numbers in range of number 1 to 30.
GOOD LUCK!
««« Discuss your solution @python_programmers_club and proper solutions will be added to our Github page »»»
««« Click here for the Solution »»»
?Ready to take this challenge? ?
#python #PracticeCode #samples #interviewQuestions #conditions #list
#PracticeCode: 0050
? FORWARD IF YOU LIKE IT ?
Task:
You have to create a program where a list two digit tuples are given and you have to arrange them in ascending order by watching 2nd elements of the tuples.
Given - [(2,5),(1,2),(4,4),(2,3)]
Output - [(1,2),(2,3),(4,4),(2,5)]
GOOD LUCK!
««« Discuss your solution @python_programmers_club and proper solutions will be added to our Github page »»»
««« Click here for the Solution »»»?Ready to take this challenge? ?
#python #PracticeCode #samples #interviewQuestions #conditions #list
#PracticeCode: 0049
? FORWARD IF YOU LIKE IT ?
Task:
You have to create a program where a list of words is given and you have to print only those words which are longer than the given number n. N has to taken as input by the user.
Given_list = ["python" , "java" , "c" , "c++" , "kotlin"]
Input - 3
Output - ["python" , "java" , "kotlin"]
GOOD LUCK!
««« Discuss your solution @python_programmers_club and proper solutions will be added to our Github page »»»
««« Click here for the Solution »»»?Ready to take this challenge? ?
#python #PracticeCode #samples #interviewQuestions #conditions #list
#PracticeCode: 0048
? FORWARD IF YOU LIKE IT ?
Task:
You have to create a program to create a dictionary. Take input of an integer (from 1 to n) and print the dictionary in (a , a**2) format.
Sample :-
Input - 4
Output - { 1 : 1 , 2 : 4 , 3 : 9 , 4 : 16}
GOOD LUCK!
««« Discuss your solution @python_programmers_club and proper solutions will be added to our Github page »»»
««« Click here for the Solution »»»?Ready to take this challenge? ?
#python #PracticeCode #samples #interviewQuestions #conditions #dict
Community chat: https://t.me/hamster_kombat_chat_2
Twitter: x.com/hamster_kombat
YouTube: https://www.youtube.com/@HamsterKombat_Official
Bot: https://t.me/hamster_kombat_bot
Game: https://t.me/hamster_kombat_bot/
Last updated 3 months, 1 week ago
Your easy, fun crypto trading app for buying and trading any crypto on the market
Last updated 3 months ago
Turn your endless taps into a financial tool.
Join @tapswap_bot
Collaboration - @taping_Guru
Last updated 3 days, 5 hours ago