Function in Python that filters integers or strings from a given list
- Get link
- X
- Other Apps
# 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))
Python
# 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))
Python
# 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))
Python
# 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))
Python
- Get link
- X
- Other Apps
Comments
Post a Comment
Write something to CodeWithAbdur!