parseList =[ 'J', ']-', 'Track-927', '4']
firstlist = parseList.split()
for s in firstlist:
if "-" in s:
print(s)
result from
-
and Track-927
are shown.
How do I remove items with fewer than a few characters from the list as a conditional statement?
python
First of all, I can't split the list, but I think the result of split the string is parseList.
Also, based on the question alone, if the number of characters is less than the reference value, I'm not sure if it's subtracted from the output list or removed from the list at all, but I wrote it thinking it was the former case.
parseList =[ 'J', ']-', 'Track-927', '4']
n = 3
for s in parseList:
if "-" in s and len(s) > n:
print(s)
Enter the desired number of characters in n
.
''.join([x for x in parseList if '-' in x and len(x) > 3])
Then do it this way
© 2024 OneMinuteCode. All rights reserved.