Unconverted data remains
Hi My Problem I have a list :- L = ['Sunday November 11 2012 9:00pm ', 'Thursday November 15 2012 7:00pm ',\ 'Friday November 16 2012 7:00pm ', 'Monday November 19 2012 7:30pm ', \ 'Friday November 23 2012 7:30pm ', 'Sunday November 25 2012 8:00pm ',\ 'Monday November 262012 7:00pm ', 'Thursday November 29 2012 6:30pm ',\ 'Saturday December 1 20125:30pm ', 'Thursday December 6 2012 9:00pm ',\ 'Sunday December 9 2012 7:00pm ', 'Friday November 9 2012 6:00pm ', \ 'Friday November 9 2012 7:00pm ', 'Friday November 9 2012 7:00pm '] final_event_time = [datetime.strptime(iterable, '%A %B %d %Y %I:%M%p') for iterable in L] and having this error Unconverted data remains . I am trying to convert all these in datetime object. -- Regards Nikhil Verma +91-958-273-3156 -- http://mail.python.org/mailman/listinfo/python-list
random number
Hi All How can we generate a 6 digit random number from a given number ? eg:- def number_generator(id): random.randint(id,99) When i am using this it is sometimes giving me five digit and sometimes 6 . I want to avoid encryption . Can i have alphanumeric 6 digit random number from this . Thanks in advance -- Regards Nikhil Verma +91-958-273-3156 -- http://mail.python.org/mailman/listinfo/python-list
Re: random number
Hi I want something to achieve like this :- def random_number(id): # I am passing it from request # do something return random_number Output random_number(5) AXR670 One input that is a number in return you are getting 6 digit alphanumeric string. I tried this s = '%06d' % random.randint(0, 99) it gives : '192862' (a string ) Thanks in advance. On Mon, Mar 26, 2012 at 11:47 AM, Daniel da Silva wrote: > If you want it as an int: > random.randint(10, 99) > > Or as a string: > s = '%06d' % random.randint(0, 99) > > > > On Mon, Mar 26, 2012 at 2:08 AM, Nikhil Verma wrote: > >> Hi All >> >> How can we generate a 6 digit random number from a given number ? >> >> eg:- >> >> def number_generator(id): >> random.randint(id,99) >> >> When i am using this it is sometimes giving me five digit and sometimes 6 >> . I want to avoid encryption . Can i have alphanumeric 6 digit random >> number from this . >> >> Thanks in advance >> >> -- >> Regards >> Nikhil Verma >> +91-958-273-3156 >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > -- Regards Nikhil Verma +91-958-273-3156 -- http://mail.python.org/mailman/listinfo/python-list
Re: random number
Hi Thanks Michael I want exactly wanted this. Great def random_number(id) ...characters = list(string.ascii_lowercase +string.ascii_uppercase +string.digits) I used this this earlier and tried then by using choice . This is great. On Mon, Mar 26, 2012 at 2:54 PM, Michael Poeltl wrote: > * Nikhil Verma [2012-03-26 08:49]: > > Hi > > > > I want something to achieve like this :- > > > > def random_number(id): # I am passing it from request > > # do something > > return random_number > > > > Output > > > > random_number(5) > > AXR670 > > > > One input that is a number in return you are getting 6 digit alphanumeric > > string. > > > > I tried this > > s = '%06d' % random.randint(0, 99) > > > > it gives : '192862' (a string ) > > > > Thanks in advance. > ah - so I misunderstood - I thought you want a permutation of a given > 6-digit number > > It's still not quite clear to me what role 'id' is playing ... so let's > check this one; > and Steven, who is maybe more experienced than I am will help us ufrther > > >>> import random, string > >>> def random_number(id): > ... characters = list(string.ascii_lowercase + > ... string.ascii_uppercase + > ... string.digits) > ... coll_rand = [] > ... for i in range(6): > ... random.shuffle(characters) > ... coll_rand.append(characters[0]) > ... return ''.join(coll_rand) > ... > >>> id = 5 > >>> print (random_number(id)) > puMHCr > >>> > > regards > Michael > > > > > > On Mon, Mar 26, 2012 at 12:10 PM, Michael Poeltl < > > michael.poe...@univie.ac.at> wrote: > > > > > * Nikhil Verma [2012-03-26 08:09]: > > > > Hi All > > > > > > > > How can we generate a 6 digit random number from a given number ? > > > what about this? > > > > > > >>> given_number=123456 > > > >>> def rand_given_number(x): > > > ... s = list(str(x)) > > > ... random.shuffle(s) > > > ... return int(''.join(s)) > > > ... > > > >>> print (rand_given_number(given_number)) > > > 653421 > > > > > > > > > > > -- > > Regards > > Nikhil Verma > > +91-958-273-3156 > > > -- > Michael Poeltl > Computational Materials Physics voice: +43-1-4277-51409 > Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) > A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at > > --- > ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12 > > --- > -- Regards Nikhil Verma +91-958-273-3156 -- http://mail.python.org/mailman/listinfo/python-list
Re: How to filter a dictionary ?
Thanks Shashank . It worked. On Tue, Apr 10, 2012 at 11:34 AM, Shashank Singh < shashank.sunny.si...@gmail.com> wrote: > > > On Mon, Apr 9, 2012 at 10:49 PM, Nikhil Verma wrote: > >> >> for_patient_type = {37: u'Test', 79: u'Real', 80: u'Real', 81: u'Real', >> 83: u'Real', 84: u'Real', 91: u'Real', 93: u'Real'} >> >> I want if the values are 'Real' give me the keys that have values 'Real' >> like this. >> >> {79:'Real'} >> {80:'Real'} >> {81:'Real'} >> {83:'Real'} >> {84:'Real'} >> {91:'Real'} >> {93:'Real'} >> > > if you want the dict filtered > > Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) > [GCC 4.2.1 (Apple Inc. build 5646)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> for_patient_type = {37: u'Test', 79: u'Real', 80: u'Real', 81: > u'Real', 83: u'Real', 84: u'Real', 91: u'Real', 93: u'Real'} > >>> dict((k, for_patient_type[k]) for k in for_patient_type if > for_patient_type[k] == 'Real') > {79: u'Real', 80: u'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/%7Eshashanksingh> > ationalpie.wordpress.com > > -- Regards Nikhil Verma +91-958-273-3156 -- http://mail.python.org/mailman/listinfo/python-list
Re: How to filter a dictionary ?
Thanks Dave and Shashank . I cleared the concept also. I got it guys. In my piece of code where i was doing this In [25]: [k for k,v in for_patient_type.iteritems() if v == "Real"] Out[25]: [80, 81, 83, 84, 91, 93, 79] thats what shashank suggest later. Thanks to you Dave.I cleared my concept which i just forgot. On Tue, Apr 10, 2012 at 12:54 PM, Shashank Singh < shashank.sunny.si...@gmail.com> wrote: > > > 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 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 >> > >> >> But that line does not iterate over the dict, it iterates over an >> iterator consisting of key/value pairs. Note he had a call to >> iteritems(). >> > > Thanks Dave. > My bad. Nikhil, you could get the data that you wanted by your initial > approach. All you needed was to either run through the generator or just > use list comprehension > > >>> g = (k for k,v in for_patient_type.iteritems() if v == 'Real') > >>> for k in g: print k > ... > 80 > 81 > 83 > 84 > 91 > 93 > 79 > >>> > > > >>> [k for k,v in for_patient_type.iteritems() if v == 'Real'] > [80, 81, 83, 84, 91, 93, 79] > > > -- > Regards > Shashank Singh > http://www.flipora.com > http://r <http://www.cse.iitb.ac.in/%7Eshashanksingh> > ationalpie.wordpress.com > > -- Regards Nikhil Verma +91-958-273-3156 -- http://mail.python.org/mailman/listinfo/python-list
DateTime objectFormatting
Hi I am using a DateTimeField in my class and want to do some tweaking with its object. class ClinicVisitDateSettings(models.Model): name = models.CharField(max_length=80,blank=True,null=True) date_created = models.DateTimeField(blank=True,null=True) def __unicode__(self): return "%s %s" % (self.name, self.date_created.strftime("%A %B %d")) The user fills Gen GI in name and date along with time. What i am able to achieve with this class object to return is :- Gen GI Monday May 7 I want that the this class should return object like this :- Gen GI Monday AM, May 7 Pancreas Tuesday PM, May 8 How can achieve AM and PM also ? with this datetime object Thanks in advance -- Regards Nikhil Verma +91-958-273-3156 -- http://mail.python.org/mailman/listinfo/python-list
Re: DateTime objectFormatting
Thanks On Wed, May 2, 2012 at 8:27 PM, Chris Rebert wrote: > On Wed, May 2, 2012 at 7:49 AM, Nikhil Verma > wrote: > > > def __unicode__(self): > > return "%s %s" % (self.name, self.date_created.strftime("%A %B > %d")) > > > > > > The user fills Gen GI in name and date along with time. > > > > What i am able to achieve with this class object to return is :- > > > > Gen GI Monday May 7 > > > > I want that the this class should return object like this :- > > > > Gen GI Monday AM, May 7 > > Pancreas Tuesday PM, May 8 > > > > How can achieve AM and PM also ? with this datetime object > > Consult the docs. > http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior: > "%p -- Locale’s equivalent of either AM or PM." > > So, strftime("%A %p, %B %d"). > > Regards, > Chris > -- Regards Nikhil Verma +91-958-273-3156 -- http://mail.python.org/mailman/listinfo/python-list
return respective values when mutiple keys are passed in dictionary
HI All I was clearing my concepts on dictionary and stuck in this problem. I have a dictionary which i have formed by using zip function on two list so that one list (which i have hardcoded) becomes the keys and the other list becomes its values. Now i want to know how can i get the values of keys at once if i pass the keys in a dictionary. Let say I have a dictionary mydict = {'a':'apple' , 'b':'boy' ,'c' : 'cat', 'd':'duck','e':'egg'} Now if i do :- mydict.get('a') 'apple' What i want is some i pass keys in get and in return i should have all the values of those keys which i pass. ## mydict.get('a','b','c')###demo for what i want 'apple','boy','cat'### Output i want # -- Regards Nikhil Verma +91-958-273-3156 -- http://mail.python.org/mailman/listinfo/python-list
Re: return respective values when mutiple keys are passed in dictionary
Thanks Arnaud List comprehension method really works nicely.sorry for late reply. On Mon, May 7, 2012 at 7:10 PM, Arnaud Delobelle wrote: > On 7 May 2012 12:31, Nikhil Verma wrote: > > HI All > > > > I was clearing my concepts on dictionary and stuck in this problem. > > I have a dictionary which i have formed by using zip function on two > list so > > that one list (which i have hardcoded) becomes the keys and the other > list > > becomes its values. > > > > Now i want to know how can i get the values of keys at once if i pass the > > keys in a dictionary. > > > > Let say I have a dictionary > > > > mydict = {'a':'apple' , 'b':'boy' ,'c' : 'cat', 'd':'duck','e':'egg'} > > > > Now if i do :- > > > > mydict.get('a') > > 'apple' > > mydict['a'] is the usual way to get the value associated with a key. > The difference is that it will throw an exception if the key doesn't > exist, which is most of the time the sanest thing to do. > > > What i want is some i pass keys in get and in return i should have all > the > > values of those keys which i pass. > > > > ## > > mydict.get('a','b','c')###demo for what i want > > 'apple','boy','cat'### Output i want > > # > > 1. You can use a list comprehension > > >>> [mydict[k] for k in 'a', 'b', 'c'] > ['apple', 'boy', 'cat'] > > 2. You can use map (for python 3.X, you need to wrap this in list(...)) > > >>> map(mydict.__getitem__, ['a', 'b', 'c']) > ['apple', 'boy', 'cat'] > > 3. You can use operator.itemgetter > > >>> from operator import itemgetter > >>> itemgetter('a', 'b', 'c')(mydict) > ('apple', 'boy', 'cat') > > -- > Arnaud > -- Regards Nikhil Verma +91-958-273-3156 -- http://mail.python.org/mailman/listinfo/python-list
tweaking random number
Hi All I want to generate a random number of 8 digits which involve 3 number and 5 digits. Like this :- def random_number(): # do something random_number() "123abcde" # first 3 numbers and 5 letters after the numbers. I am able to generate the random number 8 digit like this:- def random_number(): characters = list(string.ascii_lowercase + string.ascii_uppercase\ + string.digits) coll_rand = [] for i in range(8): random.shuffle(characters) coll_rand.append(characters[0]) return ''.join(coll_rand) This generates like this "Kkrgt56r" Thanks in advance -- Regards Nikhil Verma +91-958-273-3156 -- http://mail.python.org/mailman/listinfo/python-list
Re:rndom number tweaks
Hi Chris (That's 3 digits and 5 letters) Pretty easy. Do you want to distinguish between uppercase and lowercase letters? No i really don't care for that. I just want first three should be numbers and rest 5 are characters. "123aAbBc" Can you give examples ? -- Forwarded message -- From: Chris Angelico To: python-list@python.org Cc: Date: Wed, 9 May 2012 17:44:00 +1000 Subject: Re: tweaking random number On Wed, May 9, 2012 at 5:01 PM, Nikhil Verma wrote: > Hi All > > I want to generate a random number of 8 digits which involve 3 number and 5 > digits. (That's 3 digits and 5 letters) Pretty easy. Do you want to distinguish between uppercase and lowercase letters? Your current random_number function (btw, I wouldn't call it "number" as it isn't one) is most of one possible solution. Divide it into two parts, one part that generates the digits and another part that generates the letters. Your 'characters' template would thus be different for the two parts. There are other solutions, which involve the generation of less random numbers, but your way will work. ChrisA -- Regards Nikhil Verma +91-958-273-3156 -- http://mail.python.org/mailman/listinfo/python-list
increment date present list of tuple by weeks python
Hi All I have a list like this :- [ ('7 May monday AM Neuropancreatic'), ('8 May tuesday PM Cardiovascular')] how can i increment date in the above list for the next months on weekly basis ? [ ('7 May monday AM Neuropancreatic'),('14May monday AM Neuropancreatic')('21 May monday AM Neuropancreatic')('28 May monday AM Neuropancreatic'), ('8 May tuesday PM Cardiovascular'),('15 May monday AM Neuropancreatic'),('22 May monday AM Neuropancreatic'),('29 May monday AM Neuropancreatic')] Thanks -- Regards Nikhil Verma +91-958-273-3156 -- http://mail.python.org/mailman/listinfo/python-list
How can we covert string into Datetime object
Hi All I was going through this link http://docs.python.org/library/datetime.html#strftime-strptime-behavior. I practised strftime() and strptime() functions. Finally i stuck into a situation where i want to get the datetime object so that i can save it in my db. What i want is :- I have a string let say date_created = '11 May Friday PM ' and i want to convert it into datetime object like this datetime.datetime(2012, 5, 11, 4, 12, 44, 24734) Thanks in advance. Any help will be appreciated -- Regards Nikhil Verma +91-958-273-3156 -- http://mail.python.org/mailman/listinfo/python-list
Merge Two List of Dict
Hey guys What is the most optimal and pythonic solution forthis situation A = [{'person_id': '1', 'adop_count': '2'}, {'person_id': '3', 'adop_count': '4'}] *len(A) might be above 10L* B = [{'person_id': '1', 'village_id': '3'}, {'person_id': '3', 'village_id': '4'}] *len(B) might be above 20L* OutPut List should be C = B = [{'adop_count': '2', 'village_id': '3'}, {'adop_count': '4', 'village_id': '4'}] Thanks in advance -- https://mail.python.org/mailman/listinfo/python-list
Fwd: Merge Two List of Dict
Just editing the count it was from Indian place value notation. -- Forwarded message -- From: Nikhil Verma Date: Thu, Dec 1, 2016 at 12:44 PM Subject: Merge Two List of Dict To: python-list@python.org Hey guys What is the most optimal and pythonic solution forthis situation A = [{'person_id': '1', 'adop_count': '2'}, {'person_id': '3', 'adop_count': '4'}] *len(A) might be above 10* B = [{'person_id': '1', 'village_id': '3'}, {'person_id': '3', 'village_id': '4'}] *len(B) might be above 200* OutPut List should be C = B = [{'adop_count': '2', 'village_id': '3'}, {'adop_count': '4', 'village_id': '4'}] Thanks in advance -- [image: --] Nikhil Verma [image: http://]about.me/nikhil_verma <http://about.me/nikhil_verma?promo=email_sig> -- https://mail.python.org/mailman/listinfo/python-list