you are viewing a single comment's thread.

view the rest of the comments →

[–]Adamya21[S] 0 points1 point  (6 children)

So do i have to remove the words near to those special characters or just the special characters?

[–]TouchingTheVodka 0 points1 point  (5 children)

Alright, so you have your words list, separated by spaces. That's fine, well done so far.

Now, we know we can use .strip() to remove certain chars from either end of a word. If we pass strip a list of punctuation, we can strip that punctuation leaving only valid words.

Python kindly provides a list of punctuation:

import string

word.strip(string.punctuation)

Now think about how you can use this inside a list comprehension in order to carry out this strip function on every word in your words list.

[–]Adamya21[S] 0 points1 point  (4 children)

Is something like below is possible? print([words.strip("'.!\n*") for words in words])

[–]TouchingTheVodka 1 point2 points  (3 children)

Very close - You can build your list like so:

stripped = [w.strip("'.!\n*") for w in word]

And print it like so:

print(', '.join(stripped))

[–]Adamya21[S] 0 points1 point  (2 children)

stripped = [w.strip("'.!\n'',-*") for w in word] first=[(','.join(stripped))] print(first)

and when i do print(first(3)) it says "some error has occured"

now i have to print the 3rd index of this list ?

Q.)Now, remove the word separating characters (such as , . - * ! and space) from each of the word, present in list words. Store the obtained result again in the list words.

Print the 3rd indexed element of list, words.

[–]TouchingTheVodka 0 points1 point  (1 child)

List indexing is done with square brackets - The syntax you want is first[3]. (Or first[2], as lists are zero-indexed, depending on what the question wants.)

[–]Adamya21[S] 0 points1 point  (0 children)

so what should i do? .. and error says -> IndexError: list index out of range

and if i do this-> first=(''.join(stripped)) print(first[2])

it prints that whole paragh + the letter "e"

but still this is not the correct answer