Two different lists from a tuple generator

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
-2
down vote

favorite












I have a generator, that yields me a tuple and a function that collects information from the generator and creates two separate lists:



labels = 
dataset =
for data, label in list_data(folder):
dataset.append(data)
labels.append(label)
return dataset, labels


I'm not sure, if I'm not over-engineering here, but it feels like it's not the most pythonic way to solve it.
I've tried some ideas with list comprehension, but it always resulted in syntax errors.



Or maybe is it the best solution as it ensures readability?










share|improve this question





















  • Yes there are super-clever ways to do it. But, six month from now, will you remember how to maintain those super-clever ways? Your current way is understandable and maintainable - nothing wrong with that.
    – user535733
    Feb 17 at 0:25














up vote
-2
down vote

favorite












I have a generator, that yields me a tuple and a function that collects information from the generator and creates two separate lists:



labels = 
dataset =
for data, label in list_data(folder):
dataset.append(data)
labels.append(label)
return dataset, labels


I'm not sure, if I'm not over-engineering here, but it feels like it's not the most pythonic way to solve it.
I've tried some ideas with list comprehension, but it always resulted in syntax errors.



Or maybe is it the best solution as it ensures readability?










share|improve this question





















  • Yes there are super-clever ways to do it. But, six month from now, will you remember how to maintain those super-clever ways? Your current way is understandable and maintainable - nothing wrong with that.
    – user535733
    Feb 17 at 0:25












up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I have a generator, that yields me a tuple and a function that collects information from the generator and creates two separate lists:



labels = 
dataset =
for data, label in list_data(folder):
dataset.append(data)
labels.append(label)
return dataset, labels


I'm not sure, if I'm not over-engineering here, but it feels like it's not the most pythonic way to solve it.
I've tried some ideas with list comprehension, but it always resulted in syntax errors.



Or maybe is it the best solution as it ensures readability?










share|improve this question













I have a generator, that yields me a tuple and a function that collects information from the generator and creates two separate lists:



labels = 
dataset =
for data, label in list_data(folder):
dataset.append(data)
labels.append(label)
return dataset, labels


I'm not sure, if I'm not over-engineering here, but it feels like it's not the most pythonic way to solve it.
I've tried some ideas with list comprehension, but it always resulted in syntax errors.



Or maybe is it the best solution as it ensures readability?







python python3






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 17 at 0:06









Nav

315




315











  • Yes there are super-clever ways to do it. But, six month from now, will you remember how to maintain those super-clever ways? Your current way is understandable and maintainable - nothing wrong with that.
    – user535733
    Feb 17 at 0:25
















  • Yes there are super-clever ways to do it. But, six month from now, will you remember how to maintain those super-clever ways? Your current way is understandable and maintainable - nothing wrong with that.
    – user535733
    Feb 17 at 0:25















Yes there are super-clever ways to do it. But, six month from now, will you remember how to maintain those super-clever ways? Your current way is understandable and maintainable - nothing wrong with that.
– user535733
Feb 17 at 0:25




Yes there are super-clever ways to do it. But, six month from now, will you remember how to maintain those super-clever ways? Your current way is understandable and maintainable - nothing wrong with that.
– user535733
Feb 17 at 0:25










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Yes, there is a more Pythonic method of doing this exact interaction: zip



dataset, labels = zip(*list_data(folder))


The star (*) is important to tell zip to unzip the tuples of data. In your function then, either return just zip(*list_data(folder)) (no need for a for loop or the temporary variables, or simply use inline with no need for a function.



For future reference, note that this was more of a programming question, and thus likely better asked on stackoverflow.com.






share|improve this answer




















  • Great! That's exactly what I've been looking for. Thank you. And you are definitely right, I was quite sure I was on the SO page, not AskUbuntu.
    – Nav
    Feb 17 at 9:38










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1006926%2ftwo-different-lists-from-a-tuple-generator%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Yes, there is a more Pythonic method of doing this exact interaction: zip



dataset, labels = zip(*list_data(folder))


The star (*) is important to tell zip to unzip the tuples of data. In your function then, either return just zip(*list_data(folder)) (no need for a for loop or the temporary variables, or simply use inline with no need for a function.



For future reference, note that this was more of a programming question, and thus likely better asked on stackoverflow.com.






share|improve this answer




















  • Great! That's exactly what I've been looking for. Thank you. And you are definitely right, I was quite sure I was on the SO page, not AskUbuntu.
    – Nav
    Feb 17 at 9:38














up vote
1
down vote



accepted










Yes, there is a more Pythonic method of doing this exact interaction: zip



dataset, labels = zip(*list_data(folder))


The star (*) is important to tell zip to unzip the tuples of data. In your function then, either return just zip(*list_data(folder)) (no need for a for loop or the temporary variables, or simply use inline with no need for a function.



For future reference, note that this was more of a programming question, and thus likely better asked on stackoverflow.com.






share|improve this answer




















  • Great! That's exactly what I've been looking for. Thank you. And you are definitely right, I was quite sure I was on the SO page, not AskUbuntu.
    – Nav
    Feb 17 at 9:38












up vote
1
down vote



accepted







up vote
1
down vote



accepted






Yes, there is a more Pythonic method of doing this exact interaction: zip



dataset, labels = zip(*list_data(folder))


The star (*) is important to tell zip to unzip the tuples of data. In your function then, either return just zip(*list_data(folder)) (no need for a for loop or the temporary variables, or simply use inline with no need for a function.



For future reference, note that this was more of a programming question, and thus likely better asked on stackoverflow.com.






share|improve this answer












Yes, there is a more Pythonic method of doing this exact interaction: zip



dataset, labels = zip(*list_data(folder))


The star (*) is important to tell zip to unzip the tuples of data. In your function then, either return just zip(*list_data(folder)) (no need for a for loop or the temporary variables, or simply use inline with no need for a function.



For future reference, note that this was more of a programming question, and thus likely better asked on stackoverflow.com.







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 17 at 4:32









hunteke

2838




2838











  • Great! That's exactly what I've been looking for. Thank you. And you are definitely right, I was quite sure I was on the SO page, not AskUbuntu.
    – Nav
    Feb 17 at 9:38
















  • Great! That's exactly what I've been looking for. Thank you. And you are definitely right, I was quite sure I was on the SO page, not AskUbuntu.
    – Nav
    Feb 17 at 9:38















Great! That's exactly what I've been looking for. Thank you. And you are definitely right, I was quite sure I was on the SO page, not AskUbuntu.
– Nav
Feb 17 at 9:38




Great! That's exactly what I've been looking for. Thank you. And you are definitely right, I was quite sure I was on the SO page, not AskUbuntu.
– Nav
Feb 17 at 9:38

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1006926%2ftwo-different-lists-from-a-tuple-generator%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

pylint3 and pip3 broken

Missing snmpget and snmpwalk

How to enroll fingerprints to Ubuntu 17.10 with VFS491