[(1, red), (2, blue), (3, green)]
how do I convert to:
[[1, red], [2, blue], [3, green]]
thanks
4 7433 bvdet 2,851
Expert Mod 2GB - >>> seq1 = [(1, 'red'), (2, 'blue'), (3, 'green')]
-
>>>[list(item) for item in seq1]
-
[[1, 'red'], [2, 'blue'], [3, 'green']]
-
>>>
It's still returning a list of tuples: -
seq1 = [(1, 'red'), (2, 'blue'), (3, 'green')][list(item) for item in seq1]
-
print seq1
>>>
[(1, 'red'), (2, 'blue'), (3, 'green')]
>>>
bvdet 2,851
Expert Mod 2GB
You are not making an assignment of the new structure to seq1.
You can also use a for() loop if you don't understand list comprehensions. Iterate through the list, cast each tuple to a list, and append this list to a new, outer list.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Fuzzyman |
last post by:
Pythons internal 'pointers' system is certainly causing me a few
headaches..... When I want to copy the contents of a variable I find
it impossible to know whether I've copied the contents *or*...
|
by: beliavsky |
last post by:
Tuples, unlike lists, are immutable, which I crudely translate to mean
"their contents cannot be changed". Out of habit, I use only lists,
not tuples, in my code. But I wonder if this is poor style...
|
by: Bart Nessux |
last post by:
I understand how a Python list can be broken into smaller lists by using
slice like this:
new_small_list_1 = BIG_LIST #0-1000
new_small_list_2 = BIG_LIST #1001-2000
new_small_list_3 =...
|
by: worzel |
last post by:
I get what the difference is between a tuple and a list, but why would I
ever care about the tuple's immuutability?
Also, do you say 'too-ple' or 'chu-ple' - if you get my drift. (tomato or
tomato...
|
by: Chris Ritchey |
last post by:
Hmmm I might scare people away from this one just by the title, or
draw people in with a chalange :)
I'm writting this program in c++, however I'm using char* instead of
the string class, I am...
|
by: Dan Nordquist |
last post by:
Hey everyone.
I'm just getting my feet wet with ADSI (and VB.NET, and ASP.NET,
really), but I'm wondering if there's a way to pull a list of
distribution lists from an Exchange server using...
|
by: Sin Jeong-hun |
last post by:
List<List<T>a=param;
List<List<T>b=a;
If I change b, then a is get changed. I want another copy of a, that is
completely independent of a. I used double-nested for loop to copy each
element...
|
by: rshepard |
last post by:
I'm a bit embarrassed to have to ask for help on this, but I'm not finding
the solution in the docs I have here.
Data are assembled for writing to a database table. A representative tuple
looks...
|
by: psbasha |
last post by:
Hi,
How to remove the duplicate data from List,Tuples and Dictionary?.
Thanks in advance
PSB
|
by: little83 |
last post by:
Dear all
I have created a list contains many lists of type int by using the following line
List<List<int>> values = new List<List<int>>();
then I tried to fill one int value at each list
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |