removing spaces between 2 names

Discussion in 'Python' started by saif.shakeel@gmail.com, May 15, 2007.

  1. Guest

    Hi,
    Suppose i have a string stored in variable,how do i remove the
    space between them,like if i have the name:
    "USDT request" in a variable.i need "USDTrequest",without any space .
    Thanks
     
    , May 15, 2007
    #1
    1. Advertising

  2. Steven Howe Guest

    wrote:
    > Hi,
    > Suppose i have a string stored in variable,how do i remove the
    > space between them,like if i have the name:
    > "USDT request" in a variable.i need "USDTrequest",without any space .
    > Thanks
    >
    >

    from string import replace
    st = 'abcd acdfg xtit'
    st.replace(' ','')
    'abcdacdfgxtit'

    sph

    --
    HEX: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
     
    Steven Howe, May 15, 2007
    #2
    1. Advertising

  3. 7stud Guest

    On May 15, 12:14 am, Steven Howe <> wrote:
    > wrote:
    > > Hi,
    > > Suppose i have a string stored in variable,how do i remove the
    > > space between them,like if i have the name:
    > > "USDT request" in a variable.i need "USDTrequest",without any space .
    > > Thanks

    >
    > from string import replace
    > st = 'abcd acdfg xtit'
    > st.replace(' ','')
    > 'abcdacdfgxtit'
    >
    > sph
    >
    > --
    > HEX: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


    The methods in the string module are deprecated. Skip the import and
    use a string's built in replace() method instead:

    s = "hello world"
    result = s.replace(" ", "")
    print result
     
    7stud, May 15, 2007
    #3
  4. Guest

    On May 14, 11:00 pm, wrote:
    > Hi,
    > Suppose i have a string stored in variable,how do i remove the
    > space between them,like if i have the name:
    > "USDT request" in a variable.i need "USDTrequest",without any space .
    > Thanks


    s = "jk hij ght"
    print "".join(s.split(" "))
     
    , May 15, 2007
    #4
  5. Ant Guest

    On May 15, 7:41 am, 7stud <> wrote:
    > On May 15, 12:14 am, Steven Howe <> wrote:

    ....
    > > from string import replace
    > > st = 'abcd acdfg xtit'
    > > st.replace(' ','')
    > > 'abcdacdfgxtit'

    ....
    > The methods in the string module are deprecated. Skip the import and
    > use a string's built in replace() method instead:


    This is true, but actually Steven *is* using the string's built in
    replace method - the import isn't used in the code! Obviously the
    import was a deliberate mistake designed to see if you were
    awake... ;-)

    --
    Ant...

    http://antroy.blogspot.com/
     
    Ant, May 15, 2007
    #5
  6. On Mon, 14 May 2007 23:14:23 -0700, Steven Howe wrote:

    > wrote:
    >> Hi,
    >> Suppose i have a string stored in variable,how do i remove the
    >> space between them,like if i have the name: "USDT request" in a
    >> variable.i need "USDTrequest",without any space .
    >> Thanks
    >>
    >>

    > from string import replace
    > st = 'abcd acdfg xtit'
    > st.replace(' ','')
    > 'abcdacdfgxtit'


    The line "from string import replace" is redundant.



    --
    Steven.
     
    Steven D'Aprano, May 15, 2007
    #6
  7. wrote:
    > s = "jk hij ght"
    > print "".join(s.split(" "))


    "".join(s.split()) is enough.
    --
    Roberto Bonvallet
     
    Roberto Bonvallet, May 15, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wanwan
    Replies:
    3
    Views:
    455
    Alex Martelli
    Oct 14, 2005
  2. John B. Matthews
    Replies:
    4
    Views:
    695
    John B. Matthews
    Sep 12, 2008
  3. Roedy Green
    Replies:
    3
    Views:
    658
  4. ciapecki
    Replies:
    0
    Views:
    93
    ciapecki
    Sep 12, 2006
  5. Sfdesigner Sfdesigner
    Replies:
    5
    Views:
    184
    Chris Shea
    Aug 13, 2007
Loading...

Share This Page