Re: How to filter a dictionary ?

2012-04-10 Thread Shashank Singh
On Tue, Apr 10, 2012 at 12:16 AM, Dave Angel wrote: > On 04/10/2012 02:04 AM, Shashank Singh wrote: > > On Mon, Apr 9, 2012 at 10:49 PM, Nikhil Verma >wrote: > > > >> I am trying this but its giving me a generator object. > >> > >> In [9]: (k

Re: How to filter a dictionary ?

2012-04-09 Thread Shashank Singh
Real', 81: u'Real', 83: u'Real', 84: u'Real', 91: u'Real', 93: u'Real'} >>> If you just want the keys >>> [k for k in for_patient_type if for_patient_type[k] == 'Real'] [80, 81, 83, 84, 91, 93, 79] >>> > > I am trying this but its giving me a generator object. > > In [9]: (k for k,v in for_patient_type.iteritems() if v == 'Real') > Iterating over a dict gives you all the keys, not the key value pairs -- Regards Shashank Singh http://www.flipora.com http://r <http://www.cse.iitb.ac.in/~shashanksingh>ationalpie.wordpress.com -- http://mail.python.org/mailman/listinfo/python-list

Re: use Python to post image to Facebook

2012-04-09 Thread Shashank Singh
th of which apparently > > Forgot the refs: > > [1]https://github.com/facebook/fbconsole; > http://blog.carduner.net/2011/09/06/easy-facebook-scripting-in-python/ > > [2]https://github.com/jgorset/facepy > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regar

Re: Default value for optional parameters unexpected behaviour?

2011-06-26 Thread Shashank Singh
one assign to [] by checking for None inside the function def f(a=None): if a is None: a = [] -- Regards Shashank Singh http://rationalpie.wordpress.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to insert sorted in a list

2011-06-17 Thread Shashank Singh
his ? What is the best (fastest) > way to insert sorted in a list ? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regards Shashank Singh http://www.cse.iitb.ac.in/~shashanksingh -- http://mail.python.org/mailman/listinfo/python-list

Re: How to stop iteration

2011-06-05 Thread Shashank Singh
10, 20:10:18) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> string = 'This is a sample python programming' >>> space = 2 >>> def strsplit(stri

Re: Final state of underlying sequence in islice

2010-11-05 Thread Shashank Singh
> just stopped at 10. > > You are probably right in saying that the caller can make sure that the > parameters are such that such cases don't arise but I would still like to see > python doing the best possible thing as far as possible. > > -- Regards Sh

Final state of underlying sequence in islice

2010-11-04 Thread Shashank Singh
asy in terms of the change in code required it might break any code depending on this seemingly incorrect behavior. [1]. http://docs.python.org/library/itertools.html#itertools.islice -- Regards Shashank Singh shashank.sunny.si...@gmail.com http://www.cse.iitb.ac.in/~shashanksingh<http://www.cse.iitb.ac.in/%7Eshashanksingh> -- http://mail.python.org/mailman/listinfo/python-list

Re: That interesting notation used to describe how long a loop will take.

2010-10-04 Thread Shashank Singh
article about this > subject? I imagine that it has a concise name. > > Thanks, > > Tobiah > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regards Shashank Singh shashank.sunny.si...@gmail.com http://www.cse.iitb.ac.in/~shashanksingh<http://www.cse.iitb.ac.in/%7Eshashanksingh> -- http://mail.python.org/mailman/listinfo/python-list

Re: Reversing a List

2010-09-01 Thread Shashank Singh
ay to append to > the front of the list directly? > TIA, > beno > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Regards Shashank Singh Senior Undergraduate, Department of Computer Science and Engineering Indian Institute of Technology Bombay shashank.sunny.si...@gmail.com http://www.cse.iitb.ac.in/~shashanksingh -- http://mail.python.org/mailman/listinfo/python-list

Re: Two minor questions on Class

2010-07-30 Thread Shashank Singh
On Fri, Jul 30, 2010 at 10:53 PM, joy99 wrote: > class Person(object): >def _init_(self,name,age): >self.name=name >self.age=age > > constructor has double underscores (both as prefix and suffix) __init__ -- Regards Shashank Singh Se

Re: Fastest way to apply a function to an iterable

2010-05-26 Thread Shashank Singh
, t3.timeit(number=1000) The output for one run was: f1 0.393015034034 f2 0.476230638252 f3 0.376324923978 => simple for loop performs better than map/imap. Another problem with map/imap is that the memory cost is dependent on the length of the list (because of the intermediate mapped list store

Fastest way to apply a function to an iterable

2010-05-26 Thread Shashank Singh
suggestions will be appreciated. TIA -- Regards Shashank Singh Senior Undergraduate, Department of Computer Science and Engineering Indian Institute of Technology Bombay shashank.sunny.si...@gmail.com http://www.cse.iitb.ac.in/~shashanksingh -- http://mail.python.org/mailman/listinfo/python-list

Re: Help regarding XML file manipulation

2010-05-25 Thread Shashank Singh
y do that. HTH -S > > Thanks > ~S > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Regards Shashank Singh Senior Undergraduate, Department of Computer Science and Engineering Indian Institute of Technology Bombay shashank.sunny.si...@gmail.com http://www.cse.iitb.ac.in/~shashanksingh -- http://mail.python.org/mailman/listinfo/python-list

Re: an element from a set

2010-05-14 Thread Shashank Singh
how do you get a random > element from a set? > > random.choice(list(s)) > > is the most straightforward way and will work a lot of the time, but > how would you avoid creating the list? I can't think of a way off > hand. > > How about random.sample(s, 1)[0]? Is it ineff

Re: Fastest way to calculate leading whitespace

2010-05-08 Thread Shashank Singh
on 2 except in certain > circumstances where the value of b has already been determined for > other purposes. Solution 3 is slower due to the function overhead. > > Curious to see what other types of solutions people might have. > > Thanks, > Daniel > -- > http://mail.pyt

Re: Help needed in downloading Brown corpus

2010-05-01 Thread Shashank Singh
t of python, so unable to figure a way out. Can > someone help me in this regard either how to solve my downloading > problem or how to get Brown Corpus from some other link. > Thanks in advance. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regards Sha

Re:

2010-04-30 Thread Shashank Singh
n that in each line whatever secondary structure is coming more than > or equal to two times it should write that as final secondary structure and > if two seconday structure are coming two-two times in one line itself like: > > 4 ALA Helix Sheet Helix Sheet > > then it should w

Re: Behavior of default parameter in a function

2010-03-11 Thread Shashank Singh
;>>soo([1]) > 2 > >>>soo() > 1 > > Why foo() is incremented by 1 always when we are not passing any argument, > but this is not happening in soo() case, In which scenario we will use > these type of function.' > > Thanks > Jitendra Kumar > >

Re: Too Many Values To Unpack

2009-11-20 Thread Shashank Singh
) in fetched: > aDict[name] = {} > return aDict > def getChildren(levelDict, level = 0): > MAXLEVEL = 7 > if level > MAXLEVEL: > return #possibly the data has a cycle/loop > for (nm, dt) in levelDict: > Are you sure your key values are 2-tuples in level

(Simple?) Unicode Question

2009-08-27 Thread Shashank Singh
Hi All! I have a very simple (and probably stupid) question eluding me. When exactly is the char-set information needed? To make my question clear consider reading a file. While reading a file, all I get is basically an array of bytes. Now suppose a file has 10 bytes in it (all is data, no metad