0

Hey guys.
Im having some problems with python. I need to create a function that takes in two arguments where
the first is a sequence(string) of letters. The other is also a string but of integers, that tells me start and stop that I want to cut out from the sequence.

the fuction should return a string of the cut-out.
Can anyone give a clue?

4
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by pyTony
Featured Replies
  • 1

    Can you explain what you mean by string of integers (bytes? memoryview?) Also you must explain what you have tried to do and how the result differed from your expectations to show proper effort. Read More

1

Can you explain what you mean by string of integers (bytes? memoryview?) Also you must explain what you have tried to do and how the result differed from your expectations to show proper effort.

0

I think Pythonbeginner! means something like this: string of letters: 'abcdefgh' list of integers: [(2, 6)], how can you extract the letters from 2-6 (cefg)?

0

I think Pythonbeginner! means something like this: string of letters: 'abcdefgh' list of integers: [(2, 6)], how can you extract the letters from 2-6 (cefg)?

(cefg) what happened to "d".

Can anyone give a clue?

You can access the letters in a string by it's offset (note that the fifth offset is the sixth letter because you skip over the first 5--offest the pointer to after 5--to get to the start of the 6th):

string_of_letters='abcdefgh'
for ctr in range(2, 6):
    print string_of_letters[ctr]

Edited by woooee: n/a

0

I think Pythonbeginner! means something like this: string of letters: 'abcdefgh' list of integers: [(2, 6)], how can you extract the letters from 2-6 (cefg)?

Something like:

letters = 'abcdefgh'
indexes = [(2, 6)]
print([letters[start:stop] for start, stop in indexes])
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.