Question on Manipulating List and on Python
clp2 at rebertia.com
Thu Sep 29 12:37:28 EDT 2011
On Thu, Sep 29, 2011 at 9:11 AM, Subhabrata Banerjee
<subhagurgaon2011 at gmail.com> wrote:
> Dear Group,
> I have two questions one on list manipulation and other on Python.
> (i) I have a file of lists. Now, the first digit starts with a number
> or index, like,
> [001, "Obama", "USA", "President"]
> [002 "Major", "UK", "PM"]
> [003 "Singh", "INDIA", "PM"]
> Initially, I am reading the file and taking as
> for line in file:
> print line_word
> I am getting the above result. But, my problem is if I read the array
> position 0, which is a number then it should give me reciprocal words
> if word1==001:
> I should get line_word, line_word reciprocating the value.
> Predefining it solves the problem, but I want to capture and do as it
> iterates. If any one can help?
I'm not really clear what you mean by "reciprocal", so this is just a
guess: Perhaps you want list slicing?
>>> line_word = ["001", "Obama", "USA", "President"]
['Obama', 'USA', 'President']
> (ii) My second question is posted by one of my colleagues, what makes
> Python so fast?
CPython is actually relatively slow compared to the primary
implementations of other languages since Python highly dynamic, and
interpreted rather than compiled to machine code (normally). There are
currently some promising efforts (like PyPy) to produce a faster
More information about the Python-list