HELP! spliting strings and returning specific words
Hi, I am trying to split a string and return specific words.
I know that using string.split() turns the string into a list of specific words.
But how would I go about returning specific words? like the ones that contain certain letters?
This is my code so far:
forbid == e
word == m.split()
if forbid in m:
I want forbidword to be the words that contain the letter e.
How would I achieve that?
In addition to the iterating through lists link above, there is also list comprehension which is the simplest way to do this.
testing = ['This', 'is', 'a', 'string'
print [x for x in testing if "t" in x.lower()]
I took woooee's code and I am trying to iterate a list of characters:
When I go and run this, it only checks the first letter in the list of characters(forbidlist)
list1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
#This is what I got
for s in a:
#checks to see if the given string contains the forbidden letters.
forbidlist = list(f.lower())
userlist = m.split()
wordswithforbid = [x for x in userlist if iter_list(forbidlist) in x.lower()]
wordsnonforbid = list(set(userlist).difference(wordswithforbid))
number_of_non = len(wordsnonforbid)
return str(number_of_non) + " words don't have the forbidden letters."
iter_list is not iterator it is function, which returns first letter of the sequence a, error if a is not iterable (for example None) and None for empty sequence. One step at time!
Does Python have a built in iterator?
I was in the python interpreter and I typed in help(list)
I was looking through what came up, and I came across iter(x) - is that the iterator?
I tried using it and all I got was: <listiterator object at 0xb77029ac>
Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...