If you just have a list of strings, consider:
mylistofstrings = ["foo", "bar", "baz"]
joinedtogether = " ".join(mylistofstrings)
Now joinedtogether is the string "foo bar baz".
If you have a list of tuples of strings (say where the second element
is a pos tag), then that's a little more complicated, but just go
through the list and take out the first element of each tuple.
taggedwords = [("the", "DT"), ("dog", "NN")]
words = [word for (word,tag) in taggedwords]
Then just do a join on the variable words.
In the long run, not sure this is the best place to ask basic Python
questions :)
Cheers,
--
-- alexr
I think most of the time, that won't work in Python :) Unless you've
built a Java interpreter into your copy of Python...
On Sat, Apr 14, 2012 at 8:27 AM, FranciscoMXCA
<francisc...@gmail.com> wrote:
>
> Try yourList.toArray() as in
> http://www.exampledepot.com/egs/java.util/coll_GetArrayFromVector.html
--
-- alexr
>>> sample = [[ 'I' ,'am', 'studying','Physics'],['I','am', 'going','to','the','wedding']]
>>> output = [' '.join(x) for x in sample]
>>> print output
['I am studying Physics', 'I am going to the wedding']However, notice the final output is a list of strings (vs. the input, which was a list of lists of strings), so it's not exactly the same as what you provided as the ideal output:
[[I am studying Physics],[I am going to the wedding]]Hope this helps!
Jordi
--
You received this message because you are subscribed to the Google Groups "nltk-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nltk-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.