sql - Two Column Data Structure - Python -


If I have a list of colors, how do I know about creating a data structure in a loop

  [(u'blue ',), (u'green'), (u'black ',)]   

and a data structure is required ( Maybe 2 ('blue', 'blue'), ('green', 'green'), ('black', 'black'))

  code>  

In addition, as an additional, why (and what kind of variable) is a list of my colors that is made with the items prefixed with you and they Surrounded When I try the string ops and do not recognize it as part of the string, the data comes from a pyodbc query on a column in SQL DB (not really color!).

For example if I was modifying the first row in colours_list (not the correct syntax)

  line [2:] print row (u'ue ',) # Output   

thanks!

Using generator expression and taple unpacking:

  & gt; ; & Gt; & Gt; Color = [[('U', ''), (U'Green ',), (U' Black ',]] # If you want a Tuepal of Two-Item Tuples, then `Tupl ()` and Generator Expression & gt; ; & Gt; & Gt; Tupl (color, color for color), in colors) ((U'w ', U'blue'), ('U.Green', U'Grine '), (U' Black ', U'black')) # If you want a list of 2-item Tulips, use the list's understanding & gt; & Gt; & Gt; ['U' Grew '', 'U'Green'], (U 'Black', U'black ')] in colors [[color, color]] in color [ / Code>  

U '...' is a Unicode string literally (see)

Or you can use the str Object can be converted to:

  & gt; & Gt; & Gt; Tupe ((color (color), str (color)) for color ('blue', 'blue'), ('green', 'green'), ('black', 'black')) & Gt; & gt; Color ('blue', 'blue'), ('green', 'green'), ('black', 'black') (color for color, encoded), color .encode ())))    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -