Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108526 > unrolled thread

More list building

Started byDFS <nospam@dfs.com>
First post2016-05-11 13:21 -0400
Last post2016-05-12 08:05 -0400
Articles 7 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  More list building DFS <nospam@dfs.com> - 2016-05-11 13:21 -0400
    Re: More list building louis.a.russ@gmail.com - 2016-05-11 19:51 -0700
      Re: More list building Peter Otten <__peter__@web.de> - 2016-05-12 11:08 +0200
        Re: More list building DFS <nospam@dfs.com> - 2016-05-12 12:35 -0400
      Re: More list building DFS <nospam@dfs.com> - 2016-05-12 07:36 -0400
    Re: More list building marco.nawijn@colosso.nl - 2016-05-12 01:21 -0700
      Re: More list building DFS <nospam@dfs.com> - 2016-05-12 08:05 -0400

#108526 — More list building

FromDFS <nospam@dfs.com>
Date2016-05-11 13:21 -0400
SubjectMore list building
Message-ID<ngvph0$osu$1@dont-email.me>
Have:
p1 = ['Now', 'the', 'for', 'good']
p2 = ['is', 'time', 'all', 'men']

want
[('Now','is','the','time'), ('for','all','good','men')]

This works:

p = []
for i in xrange(0,len(p1),2):
	p.insert(i,(p1[i],p2[i],p1[i+1],p2[i+1]))


But it seems clunky.

Better way(s)?

Thanks

[toc] | [next] | [standalone]


#108539

Fromlouis.a.russ@gmail.com
Date2016-05-11 19:51 -0700
Message-ID<9983c36a-7c06-45b6-9ab8-845eee5915d9@googlegroups.com>
In reply to#108526
On Wednesday, May 11, 2016 at 1:22:09 PM UTC-4, DFS wrote:
> Have:
> p1 = ['Now', 'the', 'for', 'good']
> p2 = ['is', 'time', 'all', 'men']
> 
> want
> [('Now','is','the','time'), ('for','all','good','men')]
> 
> This works:
> 
> p = []
> for i in xrange(0,len(p1),2):
> 	p.insert(i,(p1[i],p2[i],p1[i+1],p2[i+1]))
> 
> 
> But it seems clunky.
> 
> Better way(s)?
> 
> Thanks

Would this work for you? Or do you need something more general?
t = list(zip(p1,p2))
p = [t[0]+t[1],t[2]+t[3]]

[toc] | [prev] | [next] | [standalone]


#108548

FromPeter Otten <__peter__@web.de>
Date2016-05-12 11:08 +0200
Message-ID<mailman.606.1463044097.32212.python-list@python.org>
In reply to#108539
louis.a.russ@gmail.com wrote:

> On Wednesday, May 11, 2016 at 1:22:09 PM UTC-4, DFS wrote:
>> Have:
>> p1 = ['Now', 'the', 'for', 'good']
>> p2 = ['is', 'time', 'all', 'men']
>> 
>> want
>> [('Now','is','the','time'), ('for','all','good','men')]
>> 
>> This works:
>> 
>> p = []
>> for i in xrange(0,len(p1),2):
>> p.insert(i,(p1[i],p2[i],p1[i+1],p2[i+1]))
>> 
>> 
>> But it seems clunky.
>> 
>> Better way(s)?
>> 
>> Thanks
> 
> Would this work for you? Or do you need something more general?
> t = list(zip(p1,p2))
> p = [t[0]+t[1],t[2]+t[3]]

This can be generalized as

>>> t = iter(zip(p1, p2))
>>> [a + b for a, b in zip(t, t)]
[('Now', 'is', 'the', 'time'), ('for', 'all', 'good', 'men')]

(The iter() call can be omitted in Python 3.)

[toc] | [prev] | [next] | [standalone]


#108565

FromDFS <nospam@dfs.com>
Date2016-05-12 12:35 -0400
Message-ID<nh2b6d$4oj$1@dont-email.me>
In reply to#108548
On 5/12/2016 5:08 AM, Peter Otten wrote:
>
>> On Wednesday, May 11, 2016 at 1:22:09 PM UTC-4, DFS wrote:

>>> p = []
>>> for i in xrange(0,len(p1),2):
>>> p.insert(i,(p1[i],p2[i],p1[i+1],p2[i+1]))

xrangeMethod


>>>> t = iter(zip(p1, p2))
>>>> p = [a + b for a, b in zip(t, t)]

iterMethod



Finished 100 loops of xrange in 0.0727 seconds
Finished 100 loops of iter   in 0.0495 seconds

Finished 1000 loops of xrange in 0.730 seconds
Finished 1000 loops of iter   in 0.487 seconds

Finished 10000 loops of xrange in 7.27 seconds
Finished 10000 loops of iter   in 4.79 seconds


(using Windows time.clock())





========================================================================
data scraped from
https://www.enthought.com/products/canopy/package-index/

p1 = ['7z', 'LGPL 2.1 or above', 'abstract_rendering', 'New BSD', 
'affine', 'BSD', 'amqp', 'BSD', 'ansi2html', 'GPLv3+', 'anyjson', 'BSD', 
'apipkg', 'MIT License', 'appinst', 'BSD', 'appnope', 'BSD', 
'appscript', 'Public Domain', 'apptools', 'BSD', 'arch', 'NCSA', 
'argcomplete', 'Apache 2.0', 'astroid', 'LGPL >= 2.1', 'astropy', 'BSD', 
'atom', 'BSD', 'attrs', 'MIT', 'backports.lzma', '3-clause BSD License', 
'backports_abc', 'UNKNOWN', 'backports.lzma', '3-clause BSD License', 
'basemap', 'PSF', 'bcolz', 'BSD', 'bcrypt', 'Apache', 'bdot', 'MIT', 
'BeautifulSoup4', 'MIT', 'behave', 'BSD', 'Biggus', 'LGPL3', 'billiard', 
'BSD', 'biopython', '(as-is) BSD-like', 'bitarray', 'PSF', 'blaze', 
'BSD', 'blist', 'BSD', 'blockcanvas', 'BSD', 'blosc', 'MIT', 'blz', 
'BSD', 'bokeh', 'BSD', 'boto', 'MIT', 'Bottleneck', 'BSD', 'brewer2mpl', 
'MIT', 'brood-json-schemas', 'BSD', 'bsdiff4', 'BSD', 'bz2file', 'Apache 
License, Version 2.0', 'cachecontrol', 'UNKNOWN', 'cartopy', 'LGPL', 
'casuarius', 'LGPL/BSD', 'cdecimal', 'BSD', 'celery', 'BSD', 'cffi', 
'BSD', 'chaco', 'BSD', 'chameleon', 'BSD-like', 'chardet', 'LGPL', 
'cheetah', 'MIT', 'chest', 'BSD', 'click', 'BSD', 'clint', 'ISC', 
'cloud', 'LGPL', 'cloudpickle', 'LICENSE.txt', 'codetools', 'BSD', 
'colorama', 'BSD', 'comtypes', 'MIT', 'configobj', 'BSD', 'contextlib2', 
'PSF License', 'coverage', 'BSD', 'cryptography', 'Apache 2.0', 
'cryptography_vectors', 'Apache 2.0', 'cssselect', 'BSD', 'curl', 
'MIT-like', 'CVXcanon', 'GPLv3', 'cvxopt', 'GPL v3', 'cycler', 'BSD', 
'Cython', 'Apache', 'cytoolz', 'BSD', 'dask', 'BSD', 'datashape', 'BSD', 
'pip', 'BSD', 'dill', '3-clause BSD', 'distribute', 'PSF', 'dnspython', 
'BSD-like', 'doctest-tools', 'MIT', 'docutils', 'public-domain with 
exceptions (BSD, PSF)', 'dynd_python', 'BSD-like', 'ecdsa', 'MIT', 
'enable', 'BSD', 'enaml', 'BSD', 'encore', 'BSD', 'enstaller', 'BSD', 
'enum34', 'BSD', 'envisage', 'BSD', 'epydoc', 'MIT', 'ets', 'BSD', 
'etsdevtools', 'BSD', 'etsproxy', 'BSD', 'execnet', 'MIT', 'fabric', 
'BSD', 'faulthandler', 'BSD', 'feedparser', 'BSD', 'fiona', 'BSD', 
'fipy', 'public domain', 'flake8', 'MIT', 'flask', 'BSD', 'Flask-Babel', 
'BSD', 'flask_compress', 'MIT', 'flask-cors', 'MIT', 'flask-restplus', 
'MIT', 'Flask-WTF', 'BSD', 'foolscap', 'MIT', 'freetype', 'FreeType 
License (BSD-style)', 'funcsigs', 'Apache 2.0', 'functools32', 'PSF 
license', 'future', 'MIT', 'futures', 'BSD License', 'fwrap', 'BSD', 
'GDAL', 'MIT', 'gdata', 'Apache 2.0', 'gensim', 'LGPL', 'geojson', 
'BSD', 'GEOS', 'LGPL', 'gevent', 'MIT', 'gevent_websocket', 'Apache 
2.0', 'ggplot', 'BSD', 'gitdb', 'BSD License', 'gitpython', 'BSD 
License', 'gnureadline', 'GPL', 'googlecl', 'Apache Software License 
2.0', 'graphcanvas', 'BSD', 'greenlet', 'MIT', 'grin', 'BSD', 
'gunicorn', 'MIT', 'h5py', 'BSD', 'haas', 'BSD', 'hatcher', 'BSD', 
'hdf5', 'BSD-like', 'heapdict', 'BSD', 'holoviews', 'BSD', 'html5lib', 
'MIT', 'HTMLTemplate', 'MIT', 'httpbin', 'MIT', 'httpretty', 'MIT', 
'humanize', 'MIT', 'hypothesis', 'MPL v2', 'idle', 'PSF', 'idna', 
'BSD-like', 'into', 'BSD', 'ipaddress', 'Python Software Foundation 
License', 'ipdb', 'GPL', 'ipykernel', 'BSD', 'ipyparallel', 'BSD', 
'ipython', 'BSD', 'ipython', 'BSD', 'ipython_genutils', 'BSD', 
'ipywidgets', 'BSD', 'Iris', 'LGPL3', 'iso8601', 'MIT', 'itsdangerous', 
'BSD', 'jdcal', 'BSD', 'jedi', 'MIT', 'Jinja2', 'BSD', 'joblib', 'BSD', 
'jsonpickle', 'BSD', 'jsonschema', 'MIT', 'jupyter', 'BSD', 
'jupyter_client', 'BSD', 'jupyter-console', 'BSD', 'jupyter_core', 
'BSD', 'kerberos-sspi', 'Apache 2.0', 'kernmagic', 'BSD', 'keyring', 
'PSF', 'kiwisolver', 'BSD', 'kombu', 'BSD', 'larry', 'BSD', 
'lazy_object_proxy', 'BSD', 'libblosc', 'MIT', 'libdynd', 'BSD-like', 
'libevent', 'BSD', 'libffi', 'MIT', 'libgdal', 'MIT', 'libgfortran', 
'GCC Runtime Library Exception', 'libjpeg', 'BSD', 'libopenjpeg', 'new 
BSD', 'libpcre', 'BSD-like', 'libpng', 'as-is', 'PROJ.4', 'MIT', 
'libpython', 'PSF', 'libsodium', 'ISC', 'libUDUNITS', 'BSD', 'libxml2', 
'MIT', 'libxslt', 'MIT', 'libYAML', 'MIT', 'line_profiler', 'BSD', 
'linecache2', 'UNKNOWN', 'llvm', 'BSD-like', 'llvmlite', 'BSD', 
'llvmmath', 'BSD', 'llvmpy', 'BSD', 'lmfit', 'BSD', 'lockfile', 'MIT', 
'Logbook', 'BSD', 'logilab_common', 'LGPL >= 2.1', 'lxml', 'BSD', 
'M2Crypto', 'MIT', 'mahotas', 'MIT', 'markdown', 'BSD License', 
'MarkupSafe', 'BSD', 'matplotlib', 'PSF', 'matplotlib_tests', 'PSF', 
'mayavi', 'BSD', 'mccabe', 'MIT', 'MDP', 'BSD', 'meld3', 'Repoze', 
'memory_profiler', 'BSD', 'Meta', 'BSD', 'mingw', 'mixed: public-domain, 
as-is, GPL', 'mistune', 'BSD', 'MKL', 'proprietary', 
'mkl_c_blas_abi_wrappers', 'Proprietary', 'mkl_service', 'proprietary', 
'Mlab', 'MIT', 'mock', 'BSD', 'moto', 'Apache', 'mpmath', 'BSD', 
'msgpack', 'Apache 2.0', 'msgpack', 'Apache 2.0', 'multimethods', 'MIT', 
'multipledispatch', 'BSD', 'multiprocess', 'BSD', 'nbconvert', 'BSD', 
'nbformat', 'BSD', 'ndg_httpsclient', 'Apache 2.0', 'netCDF4', 'MIT', 
'networkx', 'BSD', 'ninja', 'Apache 2.0', 'nltk', 'Apache 2.0', 'nose', 
'LGPL', 'notebook', 'BSD', 'numba', 'BSD', 'numexpr', 'MIT', 'numpy', 
'BSD', 'numpydoc', 'BSD', 'odo', 'BSD', 'okonomiyaki', 'BSD', 'opencv', 
'BSD', 'openpyxl', 'MIT/Expat', 'OWSLib', 'BSD', 'pandas', 'BSD', 
'pandas-datareader', 'BSD License', 'pandasql', 'BSD', 'param', 'BSD', 
'paramiko', 'LGPL', 'parse', 'UNKNOWN', 'parse_type', 'BSD', 'PassLib', 
'BSD', 'paste', 'MIT', 'paste', 'MIT', 'patch', 'mixed: GnuWin License, 
GPL', 'patchelf', 'GPLv3', 'path.py', 'MIT License', 'patsy', 'BSD', 
'pbr', 'Apache 2.0', 'pep8', 'BSD', 'pexpect', 'ISC license', 
'pickleshare', 'MIT', 'PIL', 'MIT', 'Pillow', 'Standard PIL License', 
'pip', 'MIT', 'plotly', 'MIT', 'ply', 'BSD', 'prettyplotlib', 'MIT', 
'progressbar', 'BSD or LGPL', 'protobuf', 'new BSD', 'protobuf_python', 
'new BSD', 'psutil', 'BSD', 'ptvs', 'Apache', 'py', 'MIT', 'pyad', 
'Apache License, Version 2.0', 'pyamg', 'BSD', 'pyasn1', 'BSD', 
'pyasn1_modules', 'BSD', 'pyaudio', 'MIT', 'Pycluster', 'PSF', 
'pycparser', 'BSD', 'pycrypto', 'as-is (BSD-like)', 'PycURL', 'MIT', 
'pydicom', 'MIT license', 'pydot', 'MIT', 'pyephem', 'LGPL', 'pyface', 
'BSD', 'pyfits', 'BSD', 'pyflakes', 'MIT', 'pygarrayimage', 'BSD', 
'pyglet', 'BSD', 'Pygments', 'BSD', 'pygrib', 'MIT', 'pyhdf', 'PSF', 
'PyKE', 'MIT', 'pylint', 'GPL >= 2', 'pymc', 'MIT', 'PyMongo', 'Apache', 
'PyMySQL', 'MIT', 'pyodbc', 'MIT', 'PyOpenGL', 'BSD', 'pyOpenSSL', 
'Apache License 2', 'pyparsing', 'MIT', 'pyproj', 'MIT', 'PyQt', 'GPL', 
'pyreadline', 'BSD', 'pysal', 'BSD', 'pySerial', 'PSF', 'pyshp', 'MIT', 
'PySide', 'LGPL', 'pysparse', 'BSD-style', 'pystache', 'MIT', 
'PyTables', 'BSD', 'pytest', 'MIT', 'pytest-httpbin', 'MIT', 'Python', 
'PSF', 'python_dateutil', 'PSF', 'python-ntlm3', 'GNU Lesser GPL v3', 
'python_sybase', 'BSD', 'python-termstyle', 'BSD', 'PythonDoc', 'PSF', 
'pytz', 'MIT', 'pyvisa', 'MIT', 'pywin32', 'PSF', 'pyxb', 'Apache 
License 2.0', 'pyxll_utils', 'BSD', 'PyYAML', 'MIT', 'pyzmq', 
'BSD-like', 'Qt', 'LGPL', 'qtconsole', 'BSD', 'queuelib', 'BSD', 
'redis', 'BSD', 'redis_py', 'MIT', 'rednose', 'BSD', 'Reportlab', 'BSD', 
'requests', 'Apache 2.0', 'requests-file', 'Apache 2.0', 
'requests_ntlm', 'ISC', 'responses', 'Apache 2.0', 'rope', 'GNU GPL', 
'rsa', 'Apache 2.0', 'runipy', 'BSD', 'sas7bdat', 'MIT', 'scandir', 'New 
BSD License', 'scientificpython', 'CeCILL', 'scikit_learn', 'BSD', 
'scikits.image', 'BSD', 'scikits.rsformats', 'BSD', 
'scikits.timeseries', 'BSD', 'scimath', 'BSD', 'SciPy', 'BSD', 'SciTE', 
'MIT', 'SCons', 'MIT', 'Scrapy', 'BSD', 'seaborn', 'BSD', 'selenium', 
'UNKNOWN', 'setuptools', 'PSF', 'Shapely', 'BSD', 'simplegeneric', 'ZPL 
2.1', 'SimPy', 'MIT', 'singledispatch', 'MIT', 'sip', 'GPL2', 'six', 
'MIT', 'smart_open', 'MIT', 'smmap', 'BSD', 'speaklater', 'BSD', 
'Sphinx', 'BSD', 'spyder', 'MIT', 'SQLAlchemy', 'MIT', 'sqlparse', 
'BSD', 'ssl_match_hostname', 'PSF', 'statsmodels', 'BSD', 'stevedore', 
'Apache 2.0', 'Supervisor', 'Repoze', 'swig', 'MIT', 'SymPy', 'BSD', 
'tabulate', 'MIT', 'tar', 'GPL', 'Tempita', 'MIT', 'testpath', 'MIT', 
'toolz', 'BSD', 'Tornado', 'Apache 2.0', 'traceback2', 'UNKNOWN', 
'traitlets', 'BSD', 'traits', 'BSD', 'traits_enaml', 'BSD', 'traitsui', 
'BSD', 'transaction', 'ZPL 2.1', 'Twisted', 'MIT', 'tzlocal', 'CC0 1.0 
Universal', 'ujson', 'BSD', 'unittest', 'BSD', 'unixodbc', 'GPL 
(libraries LGPL)', 'venusian', 'BSD-derived', 'virtualenv', 'MIT', 
'VTK', 'BSD', 'w3lib', 'BSD', 'werkzeug', 'BSD', 'wheel', 'MIT', 
'whoosh', 'Apache', 'wrapt', 'BSD', 'wxPython', 'wxWindows', 'x13as', 
'Custom', 'xray', 'Apache', 'xlrd', 'BSD', 'xlsxwriter', 'BSD', 
'xlutils', 'MIT', 'xlwings', 'BSD', 'xlwt', 'BSD', 'xray', 'Apache', 
'xz', 'Public Domain/GPL', 'yapf', 'Apache License, Version 2.0', 
'zlib', 'BSD-like', 'zope.deprecation', 'ZPL 2.1', 'zope.exceptions', 
'ZPL 2.1', 'zope.interface', 'ZPL 2.1', 'zope.sqlalchemy', 'ZPL 2.1', 
'zope.testing', 'ZPL 2.1']

p2 = ['9.20', 'The 7z compressor/decompressor', '0.5.1', 'Rendering as a 
binning process', '1.2.0', 'Matrices describing affine transformation of 
the plane', '1.4.5', 'Low-level AMQP client for Python (fork of 
amqplib)', '1.1.0', 'Convert text with ANSI color codes to HTML', 
'0.3.3', 'Wraps the best available JSON implementation available in a 
common interface', '1.4', 'apipkg: namespace control and lazy-import 
mechanism', '2.1.5', 'OS abstraction for installing application menus, 
links and icons', '0.1.0', 'Disable App Nap on OS X 10.9', '1.0.1', 
'Control AppleScriptable applications from Python.', '4.4.0', 
'Application building blocks such as scripting and help system', '3.0', 
'Routines relevant for the analysis of financial data (Univariate ARCH, 
bootstrapping, etc.).', '1.0.0', 'Bash tab completion for argparse Tab 
complete all the things!', '1.4.4', "Rebuild a new abstract syntax tree 
from Python's ast", '1.1.1', 'Community-developped Python astronomy 
tools', '0.3.10', 'Memory efficient Python objects', '15.2.0', 
'Attributes without boilerplate.', '0.0.3', "Backport of Python 3.3's 
'lzma' module for XZ/LZMA compressed files.", '0.4', "A backport of 
recent additions to the 'collections.abc' module.", '0.0.3', "Backport 
of Python 3.3's 'lzma' module for XZ/LZMA compressed files.", '1.0.7', 
'Plot data on map projections with Matplotlib', '0.12.1', 'Columnar and 
compressed data containers.', '2.0.0', 'Modern password hashing for your 
software and your servers', '0.1.7', 'Fast Dot Products on Pretty Big 
Data (powered by Bcolz)', '4.4.1', 'Sits atop an HTML or XML parser, 
providing Pythonic idioms for iterating, searching, and modifying the 
parse tree.', '1.2.5', 'behave is behaviour-driven development, Python 
style', '0.7.0', 'Virtual large arrays and lazy evaluation.', 
'3.3.0.18', 'Python multiprocessing fork with improvements and 
bugfixes', '1.66', 'Tools for biological computation', '0.8.1', 
'Efficient representation of arrays of booleans', '0.9.1', 'Data 
migration utilities', '1.3.6', 'list-like type with better asymptotic 
performance', '4.0.3', 'visual environment for creating simulation 
experiments', '1.2.8', 'Python interface to Blosc.', '0.6.2', 'blz: a 
compressed data container', '0.11.1', 'Statistical and novel interactive 
HTML plots for Python', '2.39.0', 'Boto is a Python package that 
provides interfaces to Amazon Web Services', '1.0.0', 'Optimized 
versions of some NumPy functions', '1.4.0', 'colorbrewer2.org color maps 
from Python', '0.4.0', 'brood-json-schemas is a simple package that 
contains the JSON-schemas for brood so that they may be reused across 
projects, for example for testing that hatcher submits valid JSON to 
brood.', '1.1.4', 'Binary diff and patch using the BSDIFF4-format', 
'0.98', 'Read and write bzip2-compressed files.', '0.11.5', 'httplib2 
caching for requests', '0.13.0', 'A Python package designed to make 
drawing maps for data analysis and visualisation as easy as possible', 
'1.1', 'Python-wrap of Cassowary linear constraint solver', '2.3', 'Fast 
drop-in replacement for decimal.py', '3.1.19', 'Python multiprocessing 
fork with improvements and bugfixes', '1.4.2', 'Foreign Function 
Interface for Python calling C code.', '4.5.0', 'Library for generating 
interactive 2D plots', '2.22', 'Fast HTML/XML Template Compiler.', 
'2.3.0', 'Universal encoding detector for Python 2 and 3', '2.4.4', 
'Template engine and code generation tool', '0.2.3', 'Simple on-disk 
dictionary', '6.3', 'A simple wrapper around optparse for powerful 
command line utilities.', '0.4.1', 'Python Command-line Application 
Tools', '2.4.6', "Distributed computing via PiCloud's cloud-computing 
platform", '0.1.1', 'Extended pickling support for Python objects', 
'4.2.0', 'Tools that simplify meta-programming and help the programmer 
separate data from code in Python', '0.3.6', 'Cross-platform colored 
terminal text.', '1.1.2', 'Pure Python COM package', '5.0.6', 'Simple 
but powerful configuration file reader and writer', '0.5.1', 'Backports 
and enhancements for the contextlib module', '4.0.3', 'Code coverage 
measurement for Python', '1.2.3', 'cryptography is a package which 
provides cryptographic recipes and primitives to Python developers.', 
'1.2.3', 'Test vectors for the cryptography package.', '0.9.1', 
'cssselect parses CSS3 Selectors and translates them to XPath 1.0', 
'7.43.0', 'Command line tool and library for transferring data specified 
with URL syntax', '0.0.23.3', 'A low-level library to perform the matrix 
building step in cvxpy, a convex optimization modeling software.', 
'1.1.8', 'CVXOPT -- Python Software for Convex Optimization', '0.10.0', 
'Composable style cycles', '0.23.4', 'Python-based language for writing 
C extensions for Python', '0.7.5', 'Cython implementation of Toolz: High 
performance functional utilities', '0.8.1', 'Minimal task scheduling 
abstraction', '0.5.1', 'A data description language.', '4.0.9', 
'Simplify the usage of decorators for the average programmer.', '0.2.4', 
'serialize all of python (almost)', '0.6.49', 'Download, build, install, 
upgrade, and uninstall Python packages', '1.12.0', 'A DNS toolkit for 
Python', '1.0a3', 'A small set of tools to make it easier to run doctest 
on your source files and text files.', '0.11', 'Documentation 
utilities', '0.6.6', 'The python interface to libdynd.', '0.13', 'ECDSA 
cryptographic signature library (pure python)', '4.5.1', 'Low-level, 
cross-platform drawing and interaction library', '0.9.8', 'Declarative 
language for building dynamic user interfaces', '0.6.0', 'Low-level 
modules for building applications', '4.8.11', 'Tool for installing and 
managing egg-based packages', '1.1.2', 'Python 3.4 Enum backported to 
3.3, 3.2, 3.1, 2.7, 2.6, 2.5, and 2.4.', '4.5.1', 'Extensible 
Application Framework', '3.0.1', 'Generate API documentation for Python 
modules from docstrings', '4.4.4', 'Components for constructing custom 
scientific applications', '4.0.2', 'Tools to support Python 
development', '0.1.2', 'Proxy modules for enabling code written against 
old ETS-versions to access current versions.', '1.4.1', 'Rapid 
multi-Python deployment.', '1.10.2', 'Fabric is a simple, Pythonic tool 
for remote execution and deployment', '2.4', 'Display the Python 
traceback on a crash.', '5.2.1', 'Module for downloading and parsing RSS 
and Atom feeds', '1.6.2', 'Geospatial data abstraction library', '3.1', 
'Finite volume partial differential equation solver', '2.5.1', 'The 
modular source code checker: pep8, pyflakes and co', '0.10.1', 'A 
lightweight web application framework based on Werkzeug, Jinja2 and good 
intentions.', '0.9', 'Adds i18n/l10n support to Flask applications', 
'1.3.0', 'Compress responses in your Flask app with gzip.', '2.1.2', 'A 
Flask extension adding a decorator for CORS support', '0.7.1', 'Helpers, 
syntaxic sugar and Swagger documentation for Flask-Restful', '0.11', 
'Simple integration of Flask and WTForms', '0.7.0', "A new version of 
Twisted's native RPC protocol", '2.5.3', 'High-quality portable font 
engine', '0.4', 'Python function signatures from PEP362 for Python 2.6, 
2.7 and 3.2+', '3.2.3.2', 'Backport of the functools module from Python 
3.2.3 for use on 2.7 and PyPy.', '0.15.2', 'Compatibility layer between 
Python 2 and Python 3', '3.0.3', 'Backport of the concurrent.futures 
package from Python 3.2', '0.1.1', 'Tool to wrap Fortran 77/90/95 code 
in C, Cython and Python', '2.0.1', 'Geospatial Data Abstraction 
Library', '2.0.18', 'Python client library for Google data APIs', 
'0.12.2', 'Python framework for fast Vector Space Modelling', '1.0.8', 
'Python bindings and utilities for GeoJSON', '3.5.0', 'GEOS - Geometry 
Engine, Open Source', '1.1.0', 'Python network library using greenlet 
and libevent for easy and scalable concurrency', '0.9.5', 'Websocket 
handler for the gevent pywsgi server, a Python network library', 
'0.6.8', 'ggplot for python', '0.6.4', 'Git Object Database', '1.0.0', 
'Python Git Library', '6.2.5', 'The standard Python readline extension 
statically linked against the GNU readline library.', '0.9.12', 'Use 
(some) Google services from the command line', '4.0.2', 'Interactive 
graph (network) visualization', '0.4.9', 'Lightweight in-process 
concurrent programming', '1.2.1', 'Utility which searches directories of 
source code better than grep or find', '19.4.1', 'Gunicorn is a Python 
WSGI HTTP Server for UNIX', '2.5.0', 'Python interface to the HDF 
library', '0.6.2', 'Extensible Python Test Runner', '0.10.0', 
'Surprisingly, a client to talk to the brood server (aka "Canopy 
Server").', '1.8.15.1', 'HDF5 is a data model, library, and file format 
for storing and managing large, complex data', '1.0.0', 'a heap with 
decrease-key and increase-key operations', '1.4.3', 'Stop plotting your 
data - annotate your data and let it visualize itself.', '0.999', 'HTML 
parser designed to follow the WHATWG HTML5 specification', '1.5.0', 
'htmltemplate converts [X]HTML documents into simple template object 
models easily manipulated using ordinary Python code.', '0.4.0', 'HTTP 
Request and Response Service', '0.8.10', 'HTTP client mock for Python', 
'0.5.1', 'python humanize utilities', '1.12.0', 'A library for property 
based testing', '2.7.3', 'Interactive Python shell', '2.0', 
'Internationalized Domain Names in Applications (IDNA)', '0.2.2', 'Data 
migration utilities', '1.0.15', 'IPv4/IPv6 manipulation library', 
'0.8.3', 'IPython-enabled pdb', '4.3.1', 'IPython Kernel for Jupyter', 
'5.0.1', 'Interactive Parallel Computing with IPython', '4.0.0', 
'Advanced shell for interactive and exploratory computing', '4.1.2', 
'Advanced shell for interactive and exploratory computing', '0.1.0', 
'Vestigial utilities from IPython', '4.1.1', 'IPython HTML widgets for 
Jupyter', '1.8.1', 'Iris provides a powerful, easy to use, and 
community-driven Python library for analysing and visualising 
meteorological and oceanographic data sets.', '0.1.11', 'Simple module 
to parse ISO 8601 dates', '0.24.0', 'Various helpers to pass trusted 
data to untrusted environments and back.', '1.2', 'Julian dates from 
proleptic Gregorian and Julian calendars.', '0.9.0', 'An autocompletion 
tool for Python that can be used for text editors.', '2.8', 'Template 
engine', '0.8.4', 'Lightweight pipelining: using Python functions as 
pipeline jobs.', '0.4.0', 'Serialize arbitrary object graph into JSON 
similar to Python picking', '2.4.0', 'An implementation of JSON Schema 
validation for Python', '1.0.0', 'Jupyter metapackage. Install all the 
Jupyter components in one go.', '4.2.1', 'Jupyter protocol 
implementation and client libraries', '4.1.1', 'Jupyter terminal 
console', '4.1.0', 'Jupyter core package. A base package on which 
Jupyter projects rely.', '0.1', 'Kerberos high-level windows interface', 
'0.2.0', 'Adds more magic commands to IPython', '4.0', 'Store and access 
your passwords safely on multiple platforms', '0.1.3', 'A fast 
implementation of the Cassowary constraint solver', '3.0.21', 'Messaging 
library for Python', '0.6.0', 'Label the rows, columns, or any 
dimension, of NumPy arrays', '1.2.1', 'A fast and thorough lazy object 
proxy.', '1.3.5', 'Blosc: A blocking, shuffling and loss-less 
compression library.', '0.6.6', 'LibDyND, a component of the Blaze 
project, is a C++ library for dynamic, multidimensional array', 
'2.0.21', 'C library that abstracts various OS-specific low-level event 
APIs (e.g. epoll, kqueue, etc...).', '3.0.13', 'A portable foreign 
function interface library', '2.0.1', 'Geospatial Data Abstraction 
Library', '3.0.0', 'Gfortran runtime library', '7.0', 'JPEG library', 
'2.1.0', 'open-source JPEG 2000 library', '8.35', 'PCRE - Perl 
Compatible Regular Expressions', '1.6.12', 'Portable Network Graphics 
file format library', '4.8.0', 'Library for performing conversions 
between cartographic projections', '1.2', 'MinGW import library', 
'1.0.3', 'The sodium crypto library', '2.2.17', 'Udunits is a C library 
that provides for arithmetic manipulation of units and for conversion of 
numeric values between compatible units.', '2.9.2', 'XML parser and 
toolkit', '1.1.28', 'XSLT library with XPath support', '0.1.4', 'YAML 
1.1 parser and emitter (C library)', '1.0', 'Line-by-line profiler', 
'1.0.0', 'Backports of the linecache module', '3.7.1', 'Collection of 
modular and reuable compiler and toolchain technologies', '0.9.0', 
'lightweight wrapper around basic LLVM functionality', '0.1.2', 'LLVM 
math library', '0.12.6', 'Python wrapper for the LLVM library', '0.9.2', 
'Least-Squares Minimization with Bounds and Constraints', '0.12.2', 
'Platform-independent file locking module', '0.9.0', 'A logging 
replacement for Python', '1.1.0', 'Collection of low-level Python 
packages and modules used by Logilab projects', '3.5.0', 'XML/XSLT 
library with bindings to libxml2/libxslt', '0.22.3', 'M2Crypto: A Python 
crypto and SSL toolkit', '1.3.0', 'Mahotas: Computer Vision Library', 
'2.6.5', 'Python implementation of Markdown.', '0.23', 'String class 
which safely handles XML/HTML/XHTML markup', '1.5.1', 'Interactive 2D 
plotting library', '1.5.1', 'Interactive 2D plotting library', '4.4.3', 
'Interactive 3D visualization', '0.3.1', "Plugin for flake8 for 
computing McCabe's cyclomatic complexity metrics", '3.3', 'Modular 
toolkit for Data Processing (MDP)', '1.0.2', 'meld3 is an HTML/XML 
templating engine.', '0.41', 'A module for monitoring memory usage of a 
python program', '0.4.2.dev2', 'Framework for manipulating and analyzing 
Python abstract syntax trees and bytecode', '4.8.1', 'Native Windows 
port of the GNU Compiler Collection (GCC)', '0.7.1', 'The fastest 
markdown parser in pure Python', '11.1.4', 'Intel Math Kernel Library 
(runtime)', '0.0.2', 'Compatibility library for MKL', '1.0', 'Intel MKL 
service python package.', '1.1.4', 'Mlab is a high-level python to 
Matlab bridge that lets Matlab look like a normal python library', 
'1.3.0', 'Library for test Python code', '0.4.6', 'A library that allows 
your python tests to easily mock out the boto library', '0.19', 'Python 
library for arbitrary-precision floating-point arithmetic', '0.4.2', 
'Efficient binary serialization library', '0.4.6', 'Efficient binary 
serialization library', '1.0.0', 'A simple python multidispatch.', 
'0.4.8', 'Multiple dispatch in Python.', '0.70.3', 'Package for using 
processes which mimics the threading module (FORK)', '4.1.0', 
'Converting Jupyter Notebooks', '4.0.1', 'The Jupyter Notebook format', 
'0.3.3', 'Provides enhanced HTTPS support for httplib and urllib2 using 
PyOpenSSL', '1.2.2', 'Interact with in both the new netCDF 4 and 3 
formats', '1.11', 'Create, manipulate, and analyze graphs and networks', 
'1.6.0', 'Ninja is a small build system with a focus on speed.', '3.2', 
'Suite of tools for symbolic and statistical natural language 
processing', '1.3.7', 'Extends the Python Unittest module with 
additional disocvery and running options', '4.1.0', 'UNKNOWN', '0.24.0', 
'NumPy-aware optimizing compiler for Python', '2.5', 'Fast evaluation of 
array expressions', '1.9.2', 'General-purpose multi-dimensional 
array-processing and math library', '0.5', 'Sphinx extension to support 
docstrings in Numpy format', '0.4.2', 'Data migration utilities', 
'0.14.1', "Okonomiyaki is an experimental library aimed at consolidating 
a lot of Enthought low-level code used for Enthought's eggs.", '2.4.9', 
'Real-time computer vision library', '2.3.1', 'Read and and write Excel 
OpenXML files', '0.8.8', 'OGC Web Service utility library', '0.18.0', 
'Data manipulation and analysis library', '0.2.1', 'Data readers 
extracted from the pandas codebase,should be compatible with recent 
pandas versions', '0.6.3', 'Query Pandas DataFrame objects using SQL 
syntax', '1.3.2', 'Declarative Python programming using Parameters.', 
'1.16.0', 'SSH2 protocol for secure connections to remote machines', 
'1.6.6', 'parse() is the opposite of format()', '0.3.4', 'Simplifies to 
build parse types based on the parse module', '1.6.5', 'A password 
hashing library for Python.', '1.7.5.1', 'Tools for using a Web Server 
Gateway Interface stack', '1.5.2', 'Load, configure, and compose WSGI 
applications and servers', '2.5.9', 'Patch for Windows.', '0.8', 
'PatchELF is a small utility to modify the dynamic linker and RPATH of 
ELF executables.', '8.1.1', 'A module wrapper for os.path', '0.4.1', 
'Package for describing statistical models and building design 
matrices', '1.8.1', 'Python Build Reasonableness', '1.7.0', 'Python 
style guide checker', '3.3', 'Pexpect allows easy control of interactive 
console applications.', '0.5', "Tiny 'shelve'-like database with 
concurrency support", '1.1.7', 'Image processing library', '3.1.0', 
'Python Imaging Library (Fork)', '8.1.0', 'A tool for installing and 
managing Python packages.', '1.9.6', 'Python plotting library for 
collaborative, interactive, publication-quality graphs.', '3.8', 'Python 
implementation of lex and yacc', '0.1.7', 'Painlessly create beautiful 
default matplotlib plots.', '2.3', 'A python library for text mode 
progress bars.', '2.6.1', 'Efficient binary serialization of structured 
data', '2.6.1', "Python wrappers for the 'protobuf' library", '3.3.0', 
'OS interface to processes and tasks', '2.0.0', 'Python extensions for 
Microsoft Visual Studio', '1.4.31', 'Library with cross-python path, 
ini-parsing, io, code, log facilities', '0.5.14', 'An Object-Oriented 
Active Directory management framework built on ADSI', '2.2.1', 'PyAMG: 
Algebraic Multigrid Solvers in Python', '0.1.9', 'Develop, debug and 
experiment with ASN.1-based protocols using Python', '0.0.8', 'A 
collection of ASN.1-based protocols modules.', '0.2.4', 'Python bindings 
for PortAudio', '1.50', 'Library of common clustering methods for gene 
expression data analysis', '2.14', 'C parser in python', '2.6.1', 
'Collection of cryptographic algorithms and protocols', '7.19.5', 
'PycURL is a Python interface to libcurl.', '0.9.9', 'Pure python 
package for DICOM medical file reading and writing', '1.0.28', 
"Interface to Graphviz's Dot language", '3.7.5.3', 'Scientific-grade 
astronomy routines', '5.0.0', 'GUI abstraction layer', '3.3', 'Interface 
to FITS formatted files', '1.1.0', 'Static analysis of Python code to 
detect common errors', '0.0.7', 'Allows NumPy arrays as source of OpenGL 
textures via pyglet', '1.1.4', 'Interface for developing games and other 
visually-rich applications', '2.1', 'Code syntax highlighting package 
written in Python', '1.9.9', 'Interface to World Meterological 
Organization (WMO) standard for distributing gridded data', '0.8.3', 
'Interface to the NCSA HDF4 library', '1.1.1', 'Pyke introduces a form 
of Logic Programming (inspired by Prolog) to the Python community by 
providing a knowledge-based inference engine (expert system) written in 
100% Python', '1.5.4', 'Python code static checker', '2.3.6', 'Bayesian 
estimation, particularly using Markov chain Monte Carlo', '2.8', 'Python 
driver for MongoDB', '0.6.7', 'Pure-python mysql connector that aims at 
100 % compatibility with mysqldb', '3.0.10', 'ODBC to database 
connector', '3.1.0', 'Python binding to OpenGL and related APIs', 
'0.15.1', 'Python bindings to the OpenSSL library', '2.0.3', 
'Alternative to creating simple grammers vs. tradition lex/yacc 
approach', '1.9.4', 'Cartographic transformations and geodetic 
computations', '4.11.4', 'bindings for Qt', '2.1', 'Ctypes-based 
readline for Windows', '1.7.0', 'A library of spatial analysis 
functions.', '2.7', 'Access the serial port from Python', '1.2.0', 'Pure 
Python read/write support for ESRI Shapefile format', '1.2.2', 'Python 
bindings for the cross-platform GUI toolkit Qt', '1.2.dev213', 'Fast 
sparse matrix library', '0.5.4', 'Mustache for Python', '3.2.2', 
'Hierarchical datasets for extremely large data', '2.8.7', 'Simple 
powerful testing with Python', '0.2.0', 'Easily test your HTTP library 
against a local copy of httpbin', '2.7.11', 'general-purpose, high-level 
programming language', '2.4.2', 'Extensions to the standard datetime 
module', '1.0.2', 'Python 3 compatible NTLM library', '0.39', 'Interface 
to Sybase', '0.1.10', 'console colouring for python', '2.7.3', 'Python 
documentation', '2015.7', 'World timezone definitions, modern and 
historical', '1.8', 'Interface for controlling measurement equipment', 
'220.0.0', 'Python extensions for Windows', '1.2.4', 'Python XML Schema 
Bindings', '1.0.0', 'PyXLL utility library', '3.10', 'YAML parser and 
emitter', '15.2.0', 'Binding to the ZeroMQ fast messaging library', 
'4.8.6', 'Cross-platform application and UI framework', '4.2.0', 
'Jupyter Qt console', '1.4.2', 'Collection of persistent (disk-based) 
queues', '2.6.16', 'Advanced key-value store', '2.10.3', 'Python client 
for Redis key-value store', '0.4.1', 'coloured output for nosetests', 
'3.2.0', 'Generate PDF PDF documents from dynamic data', '2.9.1', 
'Elegant and simple HTTP library for Python', '1.4', 'File transport 
adapter for Requests', '0.2.0', 'This package allows for HTTP NTLM 
authentication using the requests library.', '0.3.0', 'A utility library 
for mocking out the `requests` Python library.', '0.10.3', 'a python 
refactoring library...', '3.1.2', 'Pure-Python RSA implementation', 
'0.1.3', 'Run IPython notebooks from the command line.', '2.0.7', 'A 
sas7bdat file reader for Python', '1.1', 'scandir, a better directory 
iterator and faster os.walk()', '2.9.0', 'Library for common tasks in 
scientific computing', '0.17', 'Machine learning and data mining 
routines', '0.12.3', 'Image processing routines for SciPy', '0.1', 
'Tools for reading Remote Sensing formats', '0.91.3', 'Manipulate, 
report, and plot time series', '4.1.2', "Supports scientific and 
mathematical calculations beyond SciPy's capabilities", '0.17.0', 
'Libraries for mathematics, science, and engineering', '1.74', 'Text 
editor based on Scintilla', '2.3.3', 'Pythonic substitute for Make', 
'1.0.3', 'A high-level Python Screen Scraping framework', '0.7.0', 
'Seaborn: statistical data visualization', '2.48.0', 'Python bindings 
for Selenium', '20.2.2', 'Easily download, build, install, upgrade, and 
uninstall Python packages', '1.5.13', 'Geometric objects, predicates, 
and operations', '0.8.1', "Simple generic functions (similar to Python's 
own len(), pickle.dump(), etc.)", '3.0.5', 'Object-oriented, 
process-based discrete-event simulation language', '3.4.0.3', 'This 
library brings functools.singledispatch from Python 3.4 to Python 
2.6-3.3.', '4.17', 'SIP is the code generator used to build PyQt.', 
'1.10.0', 'Python 2 and 3 compatibility utilities', '1.2.1', 'Utils for 
streaming large files (S3, HDFS, gzip, bz2...)', '0.9.0', 'A pure git 
implementation of a sliding window memory map manager', '1.3', 
'implements a lazy string for python useful for use with gettext', 
'1.3.5', 'Creates intelligent and beautiful project documentation', 
'2.3.8', 'Scientific PYthon Development EnviRonment', '1.0.12', 'SQL 
toolkit and Object Relational Mapper', '0.1.18', 'Non-validating SQL 
parser', '3.4.0.2', 'The ssl.match_hostname() function from Python 3.4', 
'0.6.1', 'Statistical computations and models for use with SciPy', 
'1.2.0', 'Manage dynamic plugins for Python applications', '3.1.2', 
'Supervisor is a client/server system that allows its users to control a 
number of processes on UNIX-like operating systems.', '3.0.2', 'C and 
C++ wrapper and interface generator', '1.0', 'Symbolic mathematics 
library', '0.7.3', 'Pretty-print tabular data', '1.13', 'The GnuWin32 
version of tar', '0.5.3', 'Template engine', '0.2', 'Test utilities for 
code working with files and commands', '0.7.4', 'List processing tools 
and functional utilities', '4.3', 'Scalable, non-blocking web server', 
'1.4.0', 'Backports of the traceback module', '4.1.0', 'Traitlets Python 
config system', '4.5.0', 'Extend Python attributes with characteristics 
including initialization, validation, delegation, notification, and 
visualization', '0.2.1', 'Utilities for interoperation between Traits 
and Enaml.', '5.0.0', 'Traits-capable windowing framework', '1.4.4', 
'Transaction management for Python', '15.5.0', 'Event-driven networking 
engine', '1.2', 'tzinfo object for the local timezone', '1.35', 'Ultra 
fast JSON encoder and decoder for Python', '1.1.0', 'The new features in 
unittest backported to Python 2.4+.', '2.3.2', 'UNIX support for ODBC', 
'1.0', 'A library for deferring decorator actions', '14.0.1', 'Virtual 
Python Environment builder', '6.3.0', '3-D computer graphics, image 
processing, and visualization', '1.12.0', 'Library of web-related 
functions', '0.11.4', 'Advanced WSGI utility modules', '0.29.0', 'A 
built-package format for Python.', '2.7.2', 'Indexing and search 
library', '1.10.6', 'A Python module for decorators, wrappers and monkey 
patching.', '3.0.2.0', 'Python wrapper around the wxWidgets C++ GUI 
library', '1.1.19', "X-13ARIMA-SEATS is a seasonal adjustment software 
produced, distributed, and maintained by the US' Census Bureau.", 
'0.7.1', 'N-D labeled arrays and datasets in Python', '0.9.4', 'Extract 
data from Microsoft Excel (tm) spreadsheet files', '0.8.4', 'A Python 
module for creating Excel XLSX files.', '1.7.1', 'Utilities for working 
with MS Excel files.', '0.7.0', 'Make Excel fly: Interact with Excel 
from Python and vice versa.', '1.0.0', 'Create spreadsheet files 
compatible with MS Excel', '0.7.1', 'N-D labeled arrays and datasets in 
Python', '5.2.2', 'Cross-platform lossless data-compression library', 
'0.6.2', 'A formatter for Python code.', '1.2.6', 'Cross-platform 
lossless data-compression library', '4.1.2', 'Zope Deprecation 
Infrastructure', '4.0.8', 'Zope Exceptions', '4.1.3', 'Interfaces for 
Python', '0.7.6', 'Minimal Zope/SQLAlchemy transaction integration', 
'4.5.0', 'Zope testing helpers']

[toc] | [prev] | [next] | [standalone]


#108552

FromDFS <nospam@dfs.com>
Date2016-05-12 07:36 -0400
Message-ID<nh1plr$2t8$1@dont-email.me>
In reply to#108539
On 5/11/2016 10:51 PM, louis.a.russ@gmail.com wrote:
> On Wednesday, May 11, 2016 at 1:22:09 PM UTC-4, DFS wrote:
>> Have:
>> p1 = ['Now', 'the', 'for', 'good']
>> p2 = ['is', 'time', 'all', 'men']
>>
>> want
>> [('Now','is','the','time'), ('for','all','good','men')]
>>
>> This works:
>>
>> p = []
>> for i in xrange(0,len(p1),2):
>> 	p.insert(i,(p1[i],p2[i],p1[i+1],p2[i+1]))
>>
>>
>> But it seems clunky.
>>
>> Better way(s)?
>>
>> Thanks
>
> Would this work for you? Or do you need something more general?
> t = list(zip(p1,p2))
> p = [t[0]+t[1],t[2]+t[3]]


Something more general, to handle all list sizes (where size % 2 = 0).

[toc] | [prev] | [next] | [standalone]


#108545

Frommarco.nawijn@colosso.nl
Date2016-05-12 01:21 -0700
Message-ID<9f2bb67f-7812-41c9-a31c-aeb7ce2788ad@googlegroups.com>
In reply to#108526
On Wednesday, May 11, 2016 at 7:22:09 PM UTC+2, DFS wrote:
> Have:
> p1 = ['Now', 'the', 'for', 'good']
> p2 = ['is', 'time', 'all', 'men']
> 
> want
> [('Now','is','the','time'), ('for','all','good','men')]
> 
> This works:
> 
> p = []
> for i in xrange(0,len(p1),2):
> 	p.insert(i,(p1[i],p2[i],p1[i+1],p2[i+1]))
> 
> 
> But it seems clunky.
> 
> Better way(s)?
> 
> Thanks

Another way using some array manipulation:
(using Python 2.7 and numpy)

# coding: utf-8
import numpy as np

p1 = np.array(('Now', 'the', 'for', 'good'))
p2 = np.array(('is', 'time', 'all', 'men'))

p1s = np.split(p1, 2)
p2s = np.split(p2, 2)

a1 = np.vstack((p1, p2))

r1 = np.hstack((a1[:, 0], a1[:, 1]))
r2 = np.hstack((a1[:, 2], a1[:, 3]))

print r1
print r2

Produces the following output:
['Now' 'is' 'the' 'time']
['for' 'all' 'good' 'men']

[toc] | [prev] | [next] | [standalone]


#108553

FromDFS <nospam@dfs.com>
Date2016-05-12 08:05 -0400
Message-ID<nh1rao$8kf$1@dont-email.me>
In reply to#108545
On 5/12/2016 4:21 AM, marco.nawijn@colosso.nl wrote:
> On Wednesday, May 11, 2016 at 7:22:09 PM UTC+2, DFS wrote:
>> Have:
>> p1 = ['Now', 'the', 'for', 'good']
>> p2 = ['is', 'time', 'all', 'men']
>>
>> want
>> [('Now','is','the','time'), ('for','all','good','men')]
>>
>> This works:
>>
>> p = []
>> for i in xrange(0,len(p1),2):
>> 	p.insert(i,(p1[i],p2[i],p1[i+1],p2[i+1]))
>>
>>
>> But it seems clunky.
>>
>> Better way(s)?
>>
>> Thanks
>
> Another way using some array manipulation:
> (using Python 2.7 and numpy)
>
> # coding: utf-8
> import numpy as np
>
> p1 = np.array(('Now', 'the', 'for', 'good'))
> p2 = np.array(('is', 'time', 'all', 'men'))


> p1s = np.split(p1, 2)
> p2s = np.split(p2, 2)

These 2 lines aren't necessary.  Were you just trying some things and 
left them in?


> a1 = np.vstack((p1, p2))
>
> r1 = np.hstack((a1[:, 0], a1[:, 1]))
> r2 = np.hstack((a1[:, 2], a1[:, 3]))
>
> print r1
> print r2
>
> Produces the following output:
> ['Now' 'is' 'the' 'time']
> ['for' 'all' 'good' 'men']


Thanks.

How would you generalize it for all size lists (where size % 2 = 0)?





[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web