Again the shame question, I have a list of words and you need to remove them from the list by condition (without creating a new list)
words = "Here there is some kind of string and I need to remove words where more than 4 UNIC characters" Words_sp = Words.Split () x = 0. For Word in Words_sp: For i in Range (1, Len (Words_sp) +1): If Len (Set (Word)) & gt; 4: Words_Sp.pop (I)
Answer 1, Authority 100%
If you want to delete one item:
arr = ['test', 'Pest', 'Vest', 'Pest'] IF 'Pest' in Arr: Del Arr [Arr.Index ('Pest')] Print (ARR)
If all items:
arr = ['test', 'Pest', 'Vest', 'Pest'] For i in Range (LEN (ARR) - 1, -1, -1): IF Arr [i] == 'Pest': Del Arr [i] Print (ARR)
Len (Set (Word)) “- A4evsmisle 2 minutes ago
for i in range (LEN (ARR) - 1, -1, -1): IF LEN (SET (ARR [I]) & gt; 4: Del Arr [i]
Answer 2, Authority 67%
Well, if everything is new, then here:
words = "The condition that would delete all words in which more than 4 unique characters" SP = WORDS.Split () For Word in sp.copy (): If Len (Set (Word)) & gt; 4: SP.Remove (Word) Print (SP)
['in', 'tom', 'all', 'in', '4']
Explanation: You can not be content on the list and delete items from it – some elements of the list can then be missed. But you can make a copy and identify on it and then everything will be ok.
Well, either you need to go on the index as a back in advance, as done in other answers.
Well, somehow, probably:
sp = ['fiwaywap', 'fynfyphy', 'yvaav', 'autrospv', 'fusevfyv'] for sp_item in sp: IF LEN (SET (SP_IEM)) & gt; 4: sp.Remove (sp_item)
Result: [‘Fyfyfyfy’, ‘Ywaav’, ‘Fizhvfyv’]
All words where more than 4 unique characters are removed. As requested.
words = "The condition that would delete all words in which more than 4 unique characters" SP = WORDS.Split ('') For sp_item in sp [:: - 1]: IF LEN (SET (SP_IEM)) & gt; 4: sp.Remove (sp_item) sp. Out : ['in', 'Tom', 'All', 'V', '4']
And for sure – no copies.