string = 'Hello123µ►'
# every other character (even)
string_evens_set = string[1::2]
string_odds_set = string[0::2]
dict_evens = {}
for c in string_evens_set:
if c >= 'a' and c<='z' or c >= 'A' and c<='Z':
dict_evens[c] = True
list_result = []
for c in string_odds_set:
if c >= 'a' and c<='z' or c >= 'A' and c<='Z':
#if not dict_evens[c]:
if not c in dict_evens.keys():
list_result.append(c)
the_first_string = "".join(list_result)
print(the_first_string)
Well if that is not meant as:
1: select every other character
2: select not (1)
Therefore simplyfyable as "select 1,3,5,7.... character", because they are not in the second string.
second string contains 0,2,4,6,8.... characters.
Then maybe there is much wider meaning than suggested. For example, that user meant
- only letters (not digits, not local characters, not control symbols) [a-zA-Z]
- that are not in the new string (subset of every 2nd character)
string = 'Hello123µ►'
# every other character (even)
string_evens = string[1::2]
for character in
# every oddly numbered character
# string = string[::2]
string = 'Hello'
# every other character (even)
string = string[1::2]
# every oddly numbered character
# string = string[::2]
print(string)
you can do that in single line operation - assign to the string the selection you already did..
result: [H]e[l]l[o]
visible: el
P.S. please take in account the comments especially about immutability if you plan to use this with blobs or any other large strings.
P.S.S if you are going to use reserved words as variable names then no wonder you might just encounter some errors. That is reason why I do not use str as variable name. You can look up the reserved words in any programming language like for, if, else, data type names etc..