Split function in dynamic loop in pythonCalling an external command in PythonWhat are metaclasses in Python?How can I safely create a nested directory?How do you split a list into evenly sized chunks?Does Python have a ternary conditional operator?Using global variables in a functionAccessing the index in 'for' loops?How do I split a string on a delimiter in Bash?Iterating over dictionaries using 'for' loopsDoes Python have a string 'contains' substring method?
How to stop this icon from appearing on the taskbar?
In an emergency, how do I find and share my position?
Avoiding racist tropes in fantasy
Why is less being run unnecessarily by git?
Function to get current value or default from a string of two values
How can I watch the 17th (or last, if less) line in files of a folder?
Would this system work to purify water?
Co-author responds to email by mistake cc'ing the EiC
I got kicked out from graduate school in the past. How do I include this on my CV?
What are some interesting features that are common cross-linguistically but don't exist in English?
Did a flight controller ever answer Flight with a no-go?
Are modern clipless shoes and pedals that much better than toe clips and straps?
What does どうかと思う mean?
Why is my Earth simulation slower than the reality?
Rule based coloured background for labeling in QGIS
Can a PC's alignment be forcibly changed?
Why did MS-DOS applications built using Turbo Pascal fail to start with a division by zero error on faster systems?
Are there account age or level requirements for obtaining special research?
Is it appropriate for a prospective landlord to ask me for my credit report?
Why is Boris Johnson visiting only Paris & Berlin if every member of the EU needs to agree on a withdrawal deal?
What is the difference between true neutral and unaligned?
How would one country purchase another?
Can a gem used as the material component for the Magic Jar spell also be used for the Imprisonment spell?
Why were movies shot on film shot at 24 frames per second?
Split function in dynamic loop in python
Calling an external command in PythonWhat are metaclasses in Python?How can I safely create a nested directory?How do you split a list into evenly sized chunks?Does Python have a ternary conditional operator?Using global variables in a functionAccessing the index in 'for' loops?How do I split a string on a delimiter in Bash?Iterating over dictionaries using 'for' loopsDoes Python have a string 'contains' substring method?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am using a dynamic loop with split function, but unable to split:
lst= [int(x) for x in input("Enter elements").split('--')]
print(lst)
Output:
Enter elements 123456
[123456]
It doesn't split with "--"
Expected output: [1--2--3--4--5--6]
python split
add a comment |
I am using a dynamic loop with split function, but unable to split:
lst= [int(x) for x in input("Enter elements").split('--')]
print(lst)
Output:
Enter elements 123456
[123456]
It doesn't split with "--"
Expected output: [1--2--3--4--5--6]
python split
@nofinator It gives the list as it is, but doesn't split the list with ","
– Tamanbir Singh
Mar 27 at 16:44
@Gsk but even if i split it with some other symbol suppose "--" it gives me the list as it is
– Tamanbir Singh
Mar 27 at 16:46
@TamanbirSingh Please refer how to split a string
– han solo
Mar 27 at 16:50
add a comment |
I am using a dynamic loop with split function, but unable to split:
lst= [int(x) for x in input("Enter elements").split('--')]
print(lst)
Output:
Enter elements 123456
[123456]
It doesn't split with "--"
Expected output: [1--2--3--4--5--6]
python split
I am using a dynamic loop with split function, but unable to split:
lst= [int(x) for x in input("Enter elements").split('--')]
print(lst)
Output:
Enter elements 123456
[123456]
It doesn't split with "--"
Expected output: [1--2--3--4--5--6]
python split
python split
edited Mar 27 at 16:50
ekhumoro
81.7k15 gold badges126 silver badges211 bronze badges
81.7k15 gold badges126 silver badges211 bronze badges
asked Mar 27 at 16:39
Tamanbir SinghTamanbir Singh
32 bronze badges
32 bronze badges
@nofinator It gives the list as it is, but doesn't split the list with ","
– Tamanbir Singh
Mar 27 at 16:44
@Gsk but even if i split it with some other symbol suppose "--" it gives me the list as it is
– Tamanbir Singh
Mar 27 at 16:46
@TamanbirSingh Please refer how to split a string
– han solo
Mar 27 at 16:50
add a comment |
@nofinator It gives the list as it is, but doesn't split the list with ","
– Tamanbir Singh
Mar 27 at 16:44
@Gsk but even if i split it with some other symbol suppose "--" it gives me the list as it is
– Tamanbir Singh
Mar 27 at 16:46
@TamanbirSingh Please refer how to split a string
– han solo
Mar 27 at 16:50
@nofinator It gives the list as it is, but doesn't split the list with ","
– Tamanbir Singh
Mar 27 at 16:44
@nofinator It gives the list as it is, but doesn't split the list with ","
– Tamanbir Singh
Mar 27 at 16:44
@Gsk but even if i split it with some other symbol suppose "--" it gives me the list as it is
– Tamanbir Singh
Mar 27 at 16:46
@Gsk but even if i split it with some other symbol suppose "--" it gives me the list as it is
– Tamanbir Singh
Mar 27 at 16:46
@TamanbirSingh Please refer how to split a string
– han solo
Mar 27 at 16:50
@TamanbirSingh Please refer how to split a string
– han solo
Mar 27 at 16:50
add a comment |
1 Answer
1
active
oldest
votes
IIUC you want to join the chars and put them inside a list:
txt = input("Enter elements: ")
# type 123456
['--'.join(str(txt))]
=> ['1--2--3--4--5--6']
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%2f55382378%2fsplit-function-in-dynamic-loop-in-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
IIUC you want to join the chars and put them inside a list:
txt = input("Enter elements: ")
# type 123456
['--'.join(str(txt))]
=> ['1--2--3--4--5--6']
add a comment |
IIUC you want to join the chars and put them inside a list:
txt = input("Enter elements: ")
# type 123456
['--'.join(str(txt))]
=> ['1--2--3--4--5--6']
add a comment |
IIUC you want to join the chars and put them inside a list:
txt = input("Enter elements: ")
# type 123456
['--'.join(str(txt))]
=> ['1--2--3--4--5--6']
IIUC you want to join the chars and put them inside a list:
txt = input("Enter elements: ")
# type 123456
['--'.join(str(txt))]
=> ['1--2--3--4--5--6']
edited Mar 27 at 17:12
answered Mar 27 at 16:53
Óscar LópezÓscar López
188k28 gold badges251 silver badges335 bronze badges
188k28 gold badges251 silver badges335 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55382378%2fsplit-function-in-dynamic-loop-in-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
@nofinator It gives the list as it is, but doesn't split the list with ","
– Tamanbir Singh
Mar 27 at 16:44
@Gsk but even if i split it with some other symbol suppose "--" it gives me the list as it is
– Tamanbir Singh
Mar 27 at 16:46
@TamanbirSingh Please refer how to split a string
– han solo
Mar 27 at 16:50