Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7529359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:38:29+00:00 2026-05-30T04:38:29+00:00

I am trying to slice a string and insert the components into a list

  • 0

I am trying to slice a string and insert the components into a list (or index, or set, or anything), then compare them, such that

Input:

abba

Output:

['ab', 'ba']

Given a variable length of the input.

So if I slice a string

word = raw_input("Input word"
slicelength = len(word)/2
longword[:slicelength]

such that

    list = [longwordleftslice]
    list2 = [longwordrightslice]

    list2 = list2[::-1 ] ## reverse slice
    listoverall = list + list2

However, the built-in slice command [:i] specifies that i be an integer.

What can I do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:38:30+00:00Added an answer on May 30, 2026 at 4:38 am

    You can always do that..

    word = "spamspamspam"
    first_half = word[:len(word)//2]
    second_half = word[len(word)//2:]
    

    For any string s and any integer i, s == s[:i] + [:i] is invariant. Note that if len(word) is odd, you will get one more character in the second “half” than the first.

    If you are using python 3, use input as opposed to raw_input.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to create an extension that could slice any array-like class (since
I'm trying to find a way to split a String into an array of
I'm trying to precisely fit a string into a certain width. This means the
I've been trying to slice two characters out of a string using a loop,
I'm trying to take a {variable} string and cut it down for entry into
I'm trying to retrieve parameters as a string and directly feed them to jQuery's
I am new to Python. Here's what I am trying to do: Slice a
I'm trying to deploy to a slicehost slice using this config/deploy/production.rb file. I'm clueless
I'm trying to get the jQuery slider to have set values to slide to
Trying to find some simple SQL Server PIVOT examples. Most of the examples that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.