How to remove specific strings from a list

Rajeev

From the following list how can I remove elements ending with Text.

My expected result is a=['1,2,3,4']

My List is a=['1,2,3,4,5Text,6Text']

Should i use endswith to go about this problem?

Ashwini Chaudhary

Use str.endswith to filter out such items:

>>> a = ['1,2,3,4,5Text,6Text']
>>> [','.join(x for x in a[0].split(',') if not x.endswith('Text'))]
['1,2,3,4']

Here str.split splits the string at ',' and returns a list:

>>> a[0].split(',')
['1', '2', '3', '4', '5Text', '6Text']

Now filter out items from this list and then join them back using str.join.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to remove prefixes from strings?

From Java

How to remove specific substrings from a set of strings in Python?

From Java

Remove empty strings from a list of strings

From Java

Remove empty strings from list in DataFrame column

From Dev

how to remove specific row from list in angularjs

From Dev

How to remove a specific object from a List<T>

From Dev

Remove strings from elements of a list - Python

From Dev

How to remove items in a generic list from start until a specific condition

From Dev

How can I remove specific element from a list?

From Dev

Python - how to remove specific words from list?

From Dev

How to remove list of words from a list of strings?

From Dev

How to remove strings in list from another list?

From Dev

Python Remove List of Strings from List of Strings

From Dev

How to remove strings containing certain words from list FASTER

From Dev

How to remove all strings from a list of tuples python

From Dev

How can I remove members of a list of strings of equal length, based on the presence of specific characters in certain positions of the strings?

From Dev

How to grab name and remove rest of strings from python list

From Dev

how to remove specific row from list in angularjs

From Dev

How to remove a specific object from a List<T>

From Dev

How to remove items in a generic list from start until a specific condition

From Dev

How to remove double quotes from strings in a list in python?

From Dev

How can i check if the specific strings exist in a List<string> and if not to remove the indexs from the List?

From Dev

How do I remove duplicates from a list of strings?

From Dev

How to remove a specific package from dependency list of another package?

From Dev

How to remove specific empty lines from multi line strings in python?

From Dev

Python regex to remove specific pattern from a list of strings

From Dev

how to remove duplicate values from a list but want to include all empty strings from that list

From Dev

remove specific strings from a string using a loop

From Dev

Spark 2.2.0: How to remove Specific Duplicates from a Dataset of a list column

Related Related

  1. 1

    How to remove prefixes from strings?

  2. 2

    How to remove specific substrings from a set of strings in Python?

  3. 3

    Remove empty strings from a list of strings

  4. 4

    Remove empty strings from list in DataFrame column

  5. 5

    how to remove specific row from list in angularjs

  6. 6

    How to remove a specific object from a List<T>

  7. 7

    Remove strings from elements of a list - Python

  8. 8

    How to remove items in a generic list from start until a specific condition

  9. 9

    How can I remove specific element from a list?

  10. 10

    Python - how to remove specific words from list?

  11. 11

    How to remove list of words from a list of strings?

  12. 12

    How to remove strings in list from another list?

  13. 13

    Python Remove List of Strings from List of Strings

  14. 14

    How to remove strings containing certain words from list FASTER

  15. 15

    How to remove all strings from a list of tuples python

  16. 16

    How can I remove members of a list of strings of equal length, based on the presence of specific characters in certain positions of the strings?

  17. 17

    How to grab name and remove rest of strings from python list

  18. 18

    how to remove specific row from list in angularjs

  19. 19

    How to remove a specific object from a List<T>

  20. 20

    How to remove items in a generic list from start until a specific condition

  21. 21

    How to remove double quotes from strings in a list in python?

  22. 22

    How can i check if the specific strings exist in a List<string> and if not to remove the indexs from the List?

  23. 23

    How do I remove duplicates from a list of strings?

  24. 24

    How to remove a specific package from dependency list of another package?

  25. 25

    How to remove specific empty lines from multi line strings in python?

  26. 26

    Python regex to remove specific pattern from a list of strings

  27. 27

    how to remove duplicate values from a list but want to include all empty strings from that list

  28. 28

    remove specific strings from a string using a loop

  29. 29

    Spark 2.2.0: How to remove Specific Duplicates from a Dataset of a list column

HotTag

Archive