A
A
ashakhmandarov2020-06-26 20:44:54
Python
ashakhmandarov, 2020-06-26 20:44:54

How to declare a list item in a variable in python?

I have a list with words, I need to find words with commas in this list and add them to a separate list.
I'm trying to do this:
for word in words:
i = len(word) - 1
if word[i] == ",": #or the find method
word_with_comma.append(???????)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-06-26
@ashakhmandarov

word_with_comma = [word for word in words if ',' in word]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question