Skip to content
Advertisement

Tag: iteration

Python regex iteration for all combinations

I am new to regex. I am using Python 2.7 and BeautifulSoup4. I want to iterate over a particular regular expression. Required ouput : length : 5 , expression : [a-zA-Z0-9!&#%@] It should try all possible combinations e.g: [‘aaaaa’,’aaaab’,’aaaac’,…,’aaaaz’,’aaaaA’,…,’aaaaZ’,’aaaa0′,’aaaa9′,’aaaa!’,’AAA!!’] Moreover this should be possible too. If the expression is oranged{1} [‘orangea’,’oranges’]] I tried this: I realized that this is a

How to loop over grouped Pandas dataframe?

DataFrame: Code: I’m trying to just loop over the aggregated data, but I get the error: ValueError: too many values to unpack @EdChum, here’s the expected output: The output is not the problem, I wish to loop over every group. Answer df.groupby(‘l_customer_id_i’).agg(lambda x: ‘,’.join(x)) does already return a dataframe, so you cannot loop over the groups anymore. In general: df.groupby(…)

Intersecting two dictionaries

I am working on a search program over an inverted index. The index itself is a dictionary whose keys are terms and whose values are themselves dictionaries of short documents, with ID numbers as keys and their text content as values. To perform an ‘AND’ search for two terms, I thus need to intersect their postings lists (dictionaries). What is

Walking/iterating over a nested dictionary of arbitrary depth (the dictionary represents a directory tree)

Python newbie at time of writing. This came up because I want a user to be able to select a group of files from within a directory (and also any subdirectory), and unfortunately Tkinter’s default ability for selecting multiple files in a file dialog is broken on Windows 7 (http://bugs.python.org/issue8010). So I am attempting to represent a directory structure by

Getting next element while cycling through a list

When this reaches the last element, an IndexError is raised (as is the case for any list, tuple, dictionary, or string that is iterated). I actually want at that point for nextelem to equal li[0]. My rather cumbersome solution to this was Is there a better way of doing this? Answer After thinking this through carefully, I think this is

Advertisement