# returns integers only from a list
def onlyints(string):
x = list(filter(lambda e: isinstance(e, int), string))
return x
mylist = [3,6,"abdur", "space", 767, 555, 678]
print(onlyints(mylist))
# returns strings only from a list
def onlyints(string):
x = list(filter(lambda e: isinstance(e, str), string))
return x
mylist = [3,6,"abdur", "space", 767, 555, 678]
print(onlyints(mylist))
# returns integers only from a list
def onlyints(string):
return [e for e in string if isinstance(e, int)]
mylist = [3,6,"abdur", "space", 767, 555, 678]
print(onlyints(mylist))
# returns strings only from a list
def onlyints(string):
return [e for e in string if isinstance(e, str)]
mylist = [3,6,"abdur", "space", 767, 555, 678]
print(onlyints(mylist))
Comments
Post a Comment
Write something to CodeWithAbdur!