L
L
LolkaProfitka2021-11-20 23:44:34
Python
LolkaProfitka, 2021-11-20 23:44:34

How to not display strings in a list?

Wrote a function:

def diw(lust):
    print([int(i) for i in lust])
diw([1, 2, 3, 23.9, 'sad'])


How to make it so that all lines are ignored on the output and floats become integers.
Those. it should turn out like this:
def diw(lust):
    print([int(i) for i in lust])
diw([1, 2, 3, 23.9, 'sad'])
>>>> [1, 2, 3, 23]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexbprofit, 2021-11-21
@alexbprofit

def filter(array, typed):
  return [el for el in array if type(el) is not typed]

def diw(lust):
  return list(map(int, filter(lust, str)))

print(diw([1,2,3,23.9, 'sad'])) # [1,2,3,23]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question