About the Python Conversations category

Post your Python related doubts/conversations here! Topics will be visible to your Teaching Assistants and Peers.
Your doubt will be solved within 24 hours! :slight_smile:


Doubt in assignment !!!
Write a function to filter all odd numbers in the list and return the list containing only odd numbers.

My code:-

def fun(list):
for i in list:
if i%2==0:
return list

My Output:-
[5, 3, 8, 9, 1, 7]

But my output is getting wrong because it is getti ng even number 8 also.
Expected output:-[5,3,9,1,7]

So can anyone please explain where am i going wrong?

Thank you!

1 Like


don’t use list as a variable name because list is a keyword and it shouldn’t be used as a variable name.


Because when we are removing the elements of a list then the length of that list got changed again and again.
And for loop will work over the length of the list that’s why after removing the element when next iteration started the length will get reduced because of the deletion.

For getting odd numbers you need to create another list copy the content of first list to second and then use for loop with first list and remove from second list.

please solve this question

please solve this three questions.

@jhadebraj123 we will get back to you with your answer shortly.


To sum all the elements in the list



To reverse the string using user defined function


I have input all the thing correctly but the out out is not coming saying that syntax is invalid i don’t know wat to do plz help to solve out


Please send the error screenshot.

Actually i am getting syntax error


You are not giving comma after 9 in line number 40

Please help me solving this problem on Hackerrank.
And please rectify mistake in my solution below.
import re
lines = []
for i in range(N):
for i in lines:


There are lots of mistake in your code.
Try this code below: (put the indentation properly while running the code)

import re
for i in range(int(input().strip())):
data = input().strip()
matches = re.findall(r’[^<]<a href=“([^”]+)".?>(?:[^<]<\w+>)([^<]?)(?:</\w+>)*</a>', data)
if matches:
for m in matches:
print(“{0},{1}”.format(m[0].strip(), m[1].strip()))


1 Like

#program to filter out all odd numbers from a list


for i in L:
if i%2==0:




We’ll done,
Keep learning.