Part3 || Python List
Вставка
- Опубліковано 16 жов 2024
- #python #pythoninterviewquestions #datascienceforbeginners #pythonprogramming #pythontutorial #pandas
Python Pandas List comprehension - This video will help you translating for loops into list comprehension which are faster version of loops. After watching this video, you can write equivalent list comprehension for any loops.
Hello do you provide any industry level training for data scientist
Thank you for your interest! Yes, it depends on requirements. Contact Us for more details by filling the form - forms.gle/9JMNutd1aLZbBGfV6
[op1*op2 if op2%2==0 for op1 in range(4,5) for op2 in range(1,11)]
pls check and comment if it is right?
First let me know what are you trying to implement, then I can they if this logic is right or not.
But, guessing you're trying to multiply op1 with op2 when op2 is even numbers like shown in for loop logic; then the equivalent list comprehension is as given below:
## for loop
lst = []
for op1 in range(4,5):
for op2 in range(1,11):
if op2%2==0:
lst.append(op1*op2)
print(lst)
## list comprehension
[op1*op2 for op1 in range(4,5) for op2 in range(1,11) if op2%2==0]
How to contact you
To get in contact - Pls fill in the form forms.gle/9JMNutd1aLZbBGfV6