Conversion > From list.
Author: Aleksandr Chirkov
Jan. 29, 2014, 6:24 p.m.

From list to dict:

>>> a = ['hello','world','1','2']
>>> dict(zip(a[0::2], a[1::2]))
{'1': '2', 'hello': 'world'}

>>> lst1=['a','b','c','d']
>>> lst2=[1,2,3,4]

>>> dict(zip(lst1,lst2))
{'a': 1, 'c': 3, 'b': 2, 'd': 4}

>>> a = ['hello','world','1','2']
>>> i = iter(a)
>>> dict(zip(i,i))
{'1': '2', 'hello': 'world'}

>>> {a[i]: a[i+1] for i in range(0, len(a), 2)}
{'1': '2', 'hello': 'world'}


From list to tuple:

>>> lst = [1,2,3]
>>> tuple(lst)
(1, 2, 3)


>>> lst = ['foo', 'bla']
>>> map(tuple,lst)
[('f', 'o', 'o'), ('b', 'l', 'a')]


>>> x = iter([1,2,3,4,5,6,7,8,9])
>>> print zip(x, x, x)
[(1, 2, 3), (4, 5, 6), (7, 8, 9)]


>>> s,n = [1,2,3,4,5,6,7,8,9], 3
>>> zip(*[iter(s)]*n)
[(1, 2, 3), (4, 5, 6), (7, 8, 9)]


From list to string:

>>> lst = ['1', '2', '3']
>>> ''.join(lst)


If list of integers:

>>> lst = [1, 2, 3]
>>> ''.join(str(e) for e in lst)

>>> lst = [1,2,3]
>>> ''.join(map(str, lst))


From list to set:

>>> a = set(['a','b','c','d','e'])
>>> a
set(['a', 'c', 'b', 'e', 'd'])


>>> a = set(['a','b','c','d','e'])
>>> l = ['f', 'g']
>>> a |= set(l)
>>> a
set(['a', 'c', 'b', 'e', 'd', 'g', 'f'])

Cialis Dangereux Easy Buy Viagra [url=]cialis[/url] Propecia Efectos Adversos Finasteride What Is Cephalexin Monohydrate Brescia Vendo Cialis Purchase Viagra Online Pay With Check cialis price Cialis 20mg Lilly Direct Progesterone Pills No Doctor Amex Accepted Cephalexin While Breastfeeding Wellbutrin 150 Count Canada 30days - cheap cialis Prix Viagra Et Cialis Propecia Rogaine Venta De Cialis Online
cheap ed meds online ed medicines generic for erectile dysfunction ed medications best ed medication what are the best generic ed drugs online erectile dysfunction medications ed medications compared cheap ed medication ed medications online ed drugs online best erectile dysfunction medication in canada ed drugs meds for ed erectile dysfunction medications sold in canada erectile dysfunction drugs generic ed drugs cheap erectile dysfunction drugs-canada canadian erectile dysfunction drugs ED medication order erectile dysfunction medication generic drugs for erectile dysfunction erectile meds ed drug cost comparison buy erectile dysfunction drugs generic ed medication erectile dysfunction medication prices ed meds on line cheap ed drugs best erectile dysfunction drugs for sale online erectile dysfunction drugs online meds for erectile dysfunction generic ed meds erectile dysfunction drugs canada ed drug best ed drug best deal on ED meds cheap ed meds medication from canada ed erectile dysfunction generic name for ED drugs buy erectile dysfunction drugs online cheap erectile dysfunction medication generic erectile dysfunction medications erectile dysfunction drugs comparison impotence drugs online common drugs for ed generic impotence drugs ed meds cost effective ed drugs canadian erectile dysfunction drugs rosa impex pvt ltd nizagara vs viagra amoxicillin for sale overnight lexapro no perscription viagra pfizer viagra online canada pharmacy cheap viagra 100mg to buy in canada free viagra samples in canada canadian pharmacy cialis
money lenders payday lending quick easy payday loans [url=]direct lending[/url]

Leave a comment:

Web development
Review Linux
Provisioning CVS
Windows AWS
Continuous Integration
NoSql Logging Web Servers FileSystems Scala
accurev ansible apach2 apache api application approaches architecture archivation argparse arguments artifactory automation awk aws backup bash batch-scripting beaver block build built-in caching call captcha cartridge case certificates cgi chain client cloud cloudformation cluster cmd coding collections command-line commands compression conditionals conversion convert cookbook copy counter cron crud css cut cygwin daemon datatype date dd debpackage decorator delattr deploy deque dict distributed-file-systems django DNS domain driver dropbox dump elasticcache elasticsearch encryption exit ext4 extra-tags failover file filename filters for form format freetds functions gerrit getattribute gid git globals glusterfs hardware hook iam indexing inheritance init install job-interview jquery ldap linux list locals logging logs logstash lookup magicmethods mail main-menu metadata metalogger mongodb moosefs mount mssql multiplatform multithreading mysql netcat nginx nosql open-ssh openldap openshift os packaging parse partition path pattern patterns permissions pid pil pip pipe playbook pool post post-commit processes production provisioning proxy putty python python-mysql recursively redirection redis register replication repr restore return review rotation scala script search selenium server setattr settings setup shipper signals singleton slots snapshot socket splunk ssh ssh-key ssl storage str string style subprocess sugar super switch syntactic syntaxhighlighter systeminfo tail tar templatetags time tls tune2fs tuple ubuntu unicode unique unix unixodbc usage usecases uuid uwsgi variable vars version vi virtualenv volume web web-server windows with_items __getattr__