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;








-1















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]










share|improve this question


























  • @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


















-1















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]










share|improve this question


























  • @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














-1












-1








-1








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]










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • @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













1 Answer
1






active

oldest

votes


















1















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']





share|improve this answer


























    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
    );



    );













    draft saved

    draft discarded


















    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









    1















    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']





    share|improve this answer































      1















      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']





      share|improve this answer





























        1














        1










        1









        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']





        share|improve this answer















        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']






        share|improve this answer














        share|improve this answer



        share|improve this answer








        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





















            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.



















            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해