Sorting Alphanumeric Lists by Character Detection (python) Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How do I check if a list is empty?How do I sort a list of dictionaries by a value of the dictionary?Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonDoes Python have a ternary conditional operator?How do I sort a dictionary by value?Sort array of objects by string property valueHow do I list all files of a directory?
Generate an RGB colour grid
Is there any word for a place full of confusion?
When a candle burns, why does the top of wick glow if bottom of flame is hottest?
How does the secondary effect of the Heat Metal spell interact with a creature resistant/immune to fire damage?
Is grep documentation about ignoring case wrong, since it doesn't ignore case in filenames?
What is "gratricide"?
An adverb for when you're not exaggerating
Why does the remaining Rebel fleet at the end of Rogue One seem dramatically larger than the one in A New Hope?
How to react to hostile behavior from a senior developer?
What was the first language to use conditional keywords?
How to tell that you are a giant?
How to play a character with a disability or mental disorder without being offensive?
How does the math work when buying airline miles?
What are the out-of-universe reasons for the references to Toby Maguire-era Spider-Man in Into the Spider-Verse?
Selecting user stories during sprint planning
Denied boarding although I have proper visa and documentation. To whom should I make a complaint?
Monolithic + MicroServices
What is the difference between globalisation and imperialism?
Putting class ranking in CV, but against dept guidelines
How do living politicians protect their readily obtainable signatures from misuse?
A term for a woman complaining about things/begging in a cute/childish way
I am having problem understanding the behavior of below code in JavaScript
What does it mean that physics no longer uses mechanical models to describe phenomena?
How much damage would a cupful of neutron star matter do to the Earth?
Sorting Alphanumeric Lists by Character Detection (python)
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How do I check if a list is empty?How do I sort a list of dictionaries by a value of the dictionary?Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonDoes Python have a ternary conditional operator?How do I sort a dictionary by value?Sort array of objects by string property valueHow do I list all files of a directory?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm making a program that is able to open a zip file and list off the file names in alphanumeric order. Here's my code:
import zipfile
import re
zip_file = zipfile.ZipFile('/home/aaaa/exploit/example.zip','r')
for name in zip_file.namelist():
sorted(str(name in zip_file.namelist()))
print(name)
zip_file.close()
And here's the output:
example/
example/txt2.txt
example/txt3.txt
example/txt1.txt
I would like name in zip_file.namelist()
to be organized as such:
example/
example/txt1.txt
example/txt2.txt
example/txt3.txt
but I'm not very sure how to sort alphanumeric strings like this by the number only.
python sorting
add a comment |
I'm making a program that is able to open a zip file and list off the file names in alphanumeric order. Here's my code:
import zipfile
import re
zip_file = zipfile.ZipFile('/home/aaaa/exploit/example.zip','r')
for name in zip_file.namelist():
sorted(str(name in zip_file.namelist()))
print(name)
zip_file.close()
And here's the output:
example/
example/txt2.txt
example/txt3.txt
example/txt1.txt
I would like name in zip_file.namelist()
to be organized as such:
example/
example/txt1.txt
example/txt2.txt
example/txt3.txt
but I'm not very sure how to sort alphanumeric strings like this by the number only.
python sorting
add a comment |
I'm making a program that is able to open a zip file and list off the file names in alphanumeric order. Here's my code:
import zipfile
import re
zip_file = zipfile.ZipFile('/home/aaaa/exploit/example.zip','r')
for name in zip_file.namelist():
sorted(str(name in zip_file.namelist()))
print(name)
zip_file.close()
And here's the output:
example/
example/txt2.txt
example/txt3.txt
example/txt1.txt
I would like name in zip_file.namelist()
to be organized as such:
example/
example/txt1.txt
example/txt2.txt
example/txt3.txt
but I'm not very sure how to sort alphanumeric strings like this by the number only.
python sorting
I'm making a program that is able to open a zip file and list off the file names in alphanumeric order. Here's my code:
import zipfile
import re
zip_file = zipfile.ZipFile('/home/aaaa/exploit/example.zip','r')
for name in zip_file.namelist():
sorted(str(name in zip_file.namelist()))
print(name)
zip_file.close()
And here's the output:
example/
example/txt2.txt
example/txt3.txt
example/txt1.txt
I would like name in zip_file.namelist()
to be organized as such:
example/
example/txt1.txt
example/txt2.txt
example/txt3.txt
but I'm not very sure how to sort alphanumeric strings like this by the number only.
python sorting
python sorting
edited Mar 8 at 20:47
jonrsharpe
79.2k11111226
79.2k11111226
asked Mar 8 at 20:40
AstradesAstrades
33
33
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You aren't sorting the list before you loop through them. Try this:
for name in sorted(zip_file.namelist()):
print(name)
p e r f e c t t y
– Astrades
Mar 8 at 20:56
add a comment |
namelist
points to an internal object filelist. You can try to sort the output data: sorted(zip_file.namelist())
, or either you can touch the internal object zip_file.filelist.sort()
instead.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070689%2fsorting-alphanumeric-lists-by-character-detection-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You aren't sorting the list before you loop through them. Try this:
for name in sorted(zip_file.namelist()):
print(name)
p e r f e c t t y
– Astrades
Mar 8 at 20:56
add a comment |
You aren't sorting the list before you loop through them. Try this:
for name in sorted(zip_file.namelist()):
print(name)
p e r f e c t t y
– Astrades
Mar 8 at 20:56
add a comment |
You aren't sorting the list before you loop through them. Try this:
for name in sorted(zip_file.namelist()):
print(name)
You aren't sorting the list before you loop through them. Try this:
for name in sorted(zip_file.namelist()):
print(name)
answered Mar 8 at 20:48
JabJab
8,263185497
8,263185497
p e r f e c t t y
– Astrades
Mar 8 at 20:56
add a comment |
p e r f e c t t y
– Astrades
Mar 8 at 20:56
p e r f e c t t y
– Astrades
Mar 8 at 20:56
p e r f e c t t y
– Astrades
Mar 8 at 20:56
add a comment |
namelist
points to an internal object filelist. You can try to sort the output data: sorted(zip_file.namelist())
, or either you can touch the internal object zip_file.filelist.sort()
instead.
add a comment |
namelist
points to an internal object filelist. You can try to sort the output data: sorted(zip_file.namelist())
, or either you can touch the internal object zip_file.filelist.sort()
instead.
add a comment |
namelist
points to an internal object filelist. You can try to sort the output data: sorted(zip_file.namelist())
, or either you can touch the internal object zip_file.filelist.sort()
instead.
namelist
points to an internal object filelist. You can try to sort the output data: sorted(zip_file.namelist())
, or either you can touch the internal object zip_file.filelist.sort()
instead.
answered Mar 8 at 20:48
Pablo MartinezPablo Martinez
3215
3215
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070689%2fsorting-alphanumeric-lists-by-character-detection-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown