Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Hi I need to remove the duplicates in python but only when they are in a row. For example:
Input: AAABBCCDDAA
Output:ABCDA
Could you please help me? thnks.
To learn more about text processing in Python3 I recommend training on codingame.com.
def removeDuplicates(inp):
output =""
lastCharacter=""
for character in inp:
output+=character*(character!=lastCharacter)
lastCharacter=character
return output
inpTest ="AAABBCCDDAA"
print(removeDuplicates(inpTest))
ABCDA
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Input_data=[{'filename':'file_A','start_page':1,'end_page':3,'angle':90},{'filename':'file_A','start_page':6,'end_page':8,'angle':270},{'filename':'file_B','start_page':2,'end_page':3,'angle':90},{'filename':'file_B','start_page':5,'end_page':5,'angle':270}]
output=[{'filename':'file_A','page':1,'angle':90},
{'filename':'file_A','page':2,'angle':90},{'filename':'file_A','page':3,'angle':90},{'filename':'file_A','page':6,'angle':270},{'filename':'file_A','page':7,'angle':270},
{'filename':'file_A','page':8,'angle':270},{'filename':'file_B','page':2,'angle':90},
{'filename':'file_B','page':3,'angle':90},{'filename':'file_B','page':5,'angle':270}]
}
If I understood correctly, you want to do:
output = []
for d in Input_data:
for i in range(d["start_page"], d["end_page"] + 1):
output.append({'filename':d["filename"], 'page':i, 'angle':d["angle"]})
print(output)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
How can I grab the invite code from this string?
{awarded:1,inviteURL:https:\/\/www.example.com\/refer\/invite\/111A111A\/}
The expected output would be "111A111A".
Any help is appreciated
I tried it in a simple way, You could give more details for further improvement.
s = "{awarded:1,inviteURL:https:\/\/www.example.com\/refer\/invite\/111A111A\/}"
print(s[-11: -3])
This will do it with ReGex
import re
def findInvite(s):
return re.search(r"(?<=/invite\\/).*(?=\\/)",s).group()
assert findInvite("{awarded:1,inviteURL:https:\/\/www.example.com\/refer\/invite\/111A111A\/}") == "111A111A"
And if this isn't a string but a dict, then change the function to:
def findInvite(d):
s = d["inviteURL"]
return re.search(r"(?<=/invite\\/).*(?=\\/)",s).group()
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a simple bit of code what using the loop "for" prints out all the leters from input. It looks something like this:
word = str(input('Word here:'))
for i in range(0, len(word), 1):
print(word[i])
I would really like sme help
You can end keyword in print statement to remove the newline character.
print(word[i],end=" ")
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I tried to append these values in the list but it appends only else part.
I want to store these values i printed in a list. How can i achieve this??
for i in d["Cabin new"]:
if i=="nan":
print ("na")
else:
print (i[1:])
Append in both places:
res = []
for i in d["Cabin new"]:
if i=="nan":
res.append('na')
else:
res.append(i[1:])
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
these items are in a list
SF-04-08-010-MD01,
AHU-VVIP-02-003-MD03,
AHU-02-17-019-DPS03,
AHU-T3-01-PL-TS01,
EF-03-32-108-MD01,
AHU-02-16-019-MD01,
AHU-T3-01-003-MD01,
SF-04-08-010-MD01,
AHU-VVIP-02-003-MD03,
so i want a new list which should be like
SF-04-08
AHU-VVIP
AHU-02-17
AHU-T3-01
EF-03-32
AHU-02-16
AHU-T3-01
SF-04-08
AHU-VVIP-02
using python??
you can use strip like:
data = ['SF-04-08-010-MD01',
'AHU-VVIP-02-003-MD03',
'AHU-02-17-019-DPS03'
]
for item in data:
print ('-'.join(item.split('-')[:3]))
output:
SF-04-08
AHU-VVIP-02
AHU-02-17