Re: [BangPypers] Python dictionaries, deleting elements while iterating.

2013-02-25 Thread Navin Kabra
Anand Chitipothu writes: > loop. In Python 3, it can be written as a dictionary-comprehension. Dictionary and set comprehensions are also available in Python 2.7 ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/b

Re: [BangPypers] help to understand this code

2013-02-25 Thread Gopalakrishnan Subramani
I still recommend you go through the fundamentals of Python, I don't see any hurry in learning something new. Starts with printing "hello world", then conditions, loops, functions, Class, Objects. You don't need more than 2 weeks for this homework. Couple of late nights and weekends help you, It is

Re: [BangPypers] Listing files in a folder using python

2013-02-25 Thread Baishampayan Ghose
I didn't read the whole PHP code, but I guess you are trying to scan a directory for files, etc. This can be accomplished using the os.walk function in Python - http://docs.python.org/2/library/os.html#os.walk Regards, BG On Tue, Feb 26, 2013 at 8:19 AM, T S KAMATH wrote: > as a newbie to python

[BangPypers] Listing files in a folder using python

2013-02-25 Thread T S KAMATH
as a newbie to python, I am looking for some advance examples for some functions.. so that my learning curve is short.. I have used a code in php http://www.php.net/manual/en/function.scandir.php#109115, which works fine, My question is can a similar featured listing be done in Python.. if yo

Re: [BangPypers] help to understand this code

2013-02-25 Thread T S KAMATH
My Apologies for yesterdays post.. It was click "send" instead of "draft".. Moderator pls "del" the earlier post. I am no developer nor a hardcore programer. I just use open Source to find "work around" to issues and or to automate. all my stuff is open source and free to use. Hence pls excuse

Re: [BangPypers] Python dictionaries, deleting elements while iterating

2013-02-25 Thread Thava Alagu
Hi, Earlier answers have rightly pointed out elegant solutions, out of which dictionary comprehension is the most pythonic. btw, dictionary comprehension is available in Python 2.7 and 3+. with regards to why deleting while iterating is a problem -- it is like cutting the branch of the tree whi

Re: [BangPypers] Python dictionaries, deleting elements while iterating.

2013-02-25 Thread ragsagar
On Mon, Feb 25, 2013 at 10:15 PM, Anand Chitipothu wrote: > > > I think, the second solution I suggested is more Pythonic than using a for > loop. In Python 3, it can be written as a dictionary-comprehension. > > dictionary = {(k, v) for k, v in dictionary.items() if v != 1} > > True. Using dictio

Re: [BangPypers] Python dictionaries, deleting elements while iterating.

2013-02-25 Thread Anand Chitipothu
On Mon, Feb 25, 2013 at 9:50 PM, ragsagar wrote: > On Mon, Feb 25, 2013 at 9:33 PM, Anand Chitipothu >wrote: > > > > > You can iterate over items: > > > > for key, value in dictionary.items(): > > if value == 1: > > del dictionary[key] > > > > I think in Python 3.*, dict.items() retu

Re: [BangPypers] Python dictionaries, deleting elements while iterating.

2013-02-25 Thread ragsagar
On Mon, Feb 25, 2013 at 9:33 PM, Anand Chitipothu wrote: > > You can iterate over items: > > for key, value in dictionary.items(): > if value == 1: > del dictionary[key] > I think in Python 3.*, dict.items() returns iterator. If so it won't work in Python 3.* . So converting it to lis

Re: [BangPypers] Python dictionaries, deleting elements while iterating.

2013-02-25 Thread Anand Chitipothu
On Mon, Feb 25, 2013 at 8:51 PM, Pranjal Mittal < pranjal.mittal.ec...@iitbhu.ac.in> wrote: > > Hi all, > > I was writing a piece of code that deletes items from Python Dictionaries > when a certain condition is met. while iterating over the dictionary. > > http://dpaste.com/hold/995010/ > > Howeve

[BangPypers] Python dictionaries, deleting elements while iterating.

2013-02-25 Thread Pranjal Mittal
Hi all, I was writing a piece of code that deletes items from Python Dictionaries when a certain condition is met. while iterating over the dictionary. http://dpaste.com/hold/995010/ However that leads to a RunTime Error. Though I figured out an alternate solution, I still wonder why shouldn't s

Re: [BangPypers] help to understand this code..

2013-02-25 Thread Srikanth Kamath
Oops Regards Srikanth Kamath, BDM SAARC Sent from my Mobil Device ~ I unable to access emails from laptop, maybe in meeting or ~~travelling hence response will be delayed, thanks for understanding and cooperation. On 25-Feb-2013, at 8:14 PM, Gora Mohanty wrote: On 25 February 2013 19:41, T

Re: [BangPypers] help to understand this code..

2013-02-25 Thread Gora Mohanty
On 25 February 2013 19:41, T S KAMATH wrote: > Hi, > > I have no cue on php and its usage.. i am stuck.. I just wanted to list all > the files and dir of the folder on webpage and unfortunately the web-server > is set up for php.. [...] So, why are you asking here? It is off-topic, and you woul

[BangPypers] help to understand this code..

2013-02-25 Thread T S KAMATH
Hi, I have no cue on php and its usage.. i am stuck.. I just wanted to list all the files and dir of the folder on webpage and unfortunately the web-server is set up for php.. http://www.php.net/manual/en/function.scandir.php#109115 "; foreach($directories as $entry) { if(is_dir($dir_