>>> from string import punctuation
>>> def check_spec_characters(text):
res = [i for i in punctuation if i in text]
if res:
print('YES')
else:
print('NO')
>>> text = 'Expression syntax is straightforward: the operators +, -, * and / work as expected'
>>> check_spec_characters(text)
YES
>>> text = 'Expression syntax is straightforward the operators work as expected'
>>> check_spec_characters(text)
NO
......
if res:
print('Special characters found in text: {}'.format(res))
......
>>> text = 'Expression syntax is straightforward: the operators +, -, * and / work as expected'
>>> check_spec_characters(text)
Special characters found in text: ['*', '+', ',', '-', '/', ':']
>>> symbols_start = '23456789TJQKA'
>>> symbols_heap = 'A926K'
>>> symbols_heap_sort = ''.join(i for i in symbols_start if i in symbols_heap)
>>> symbols_heap_sort
'269KA'
>>> import re
>>> data = ['15', 5, '34k', 'de', '120', 40, 18.6, 've', 'v8', 'v200', 'a10c', 'a5b']
# Выбираем числа и строки, с чисел начинающиеся
>>> numbers_mix = [i for i in data if str(i)[0].isdigit()]
>>> numbers_mix
['15', 5, '34k', '120', 40, 18.6]
# Сортируем
>>> digit = '(\d+)'
>>> numbers_mix_sort = sorted(numbers_mix, key=lambda x: int(re.split(digit, str(x))[1]))
>>> numbers_mix_sort
[5, '15', 18.6, '34k', 40, '120']
# Выбираем оставшиеся строки
>>> text_mix = [i for i in data if i not in numbers_mix]
>>> text_mix
['de', 've', 'v8', 'v200', 'a10c', 'a5b']
#Сортируем
>>> text_mix_sort = sorted(text_mix, key=lambda x: (re.split(digit, x)[0], int(re.split(digit, x+'0')[1])))
>>> text_mix_sort
['a5b', 'a10c', 'de', 'v8', 'v200', 've']
# Итого
>>> result = numbers_mix_sort + text_mix_sort
>>> result
[5, '15', 18.6, '34k', 40, '120', 'a5b', 'a10c', 'de', 'v8', 'v200', 've']
def my_func():
return 'This is my func result'
In [1]: import my_file
In [2]: result = my_file.my_func()
In [3]: result
Out[3]: 'This is my func result'
In [4]: from my_file import my_func
In [5]: result = my_func()
In [6]: result
Out[6]: 'This is my func result'
# my_list = your_list
>>> import itertools
>>> grouped_values = []
>>> my_values = []
>>> value = ''
>>> for _, group in itertools.groupby(my_list, len):
grouped_values.append(list(group))
>>> zipped_values = [list(zip(*i)) for i in grouped_values]
>>> for i in zipped_values:
for u in i:
if len(set(u)) == 1:
value += u[0]
else:
my_values.append(value)
value = ''
break
# for i in my_values: print(i)
решил окончательно, холивары не нужны
while True:
question = int(input('Введите число: '))
# some code
if question == some_value:
break
while True:
question = int(input('Введите число: '))
if question == 1:
print('I am 1')
elif question == 2:
print('I am 2')
elif question == 3:
break
input()
>>> import re
>>> def sent_count(text):
new_text = re.sub(r'[.!?]\s', r'|', text)
sent_num = len(new_text.split('|'))
print('В этом тексте {} предложения.'.format(sent_num))
>>> text = 'Чиполлино был сыном Чиполлоне. И было у него семь братьев: Чиполлетто и так далее – самые подходящие имена. Люди они были хорошие, да только не везло им в жизни.'
>>> sent_count(text)
В этом тексте 3 предложения.
>>> text = "Чиполлино был сыном Чиполлоне?! И было у него семь братьев: Чиполлетто и так далее – самые подходящие имена. Люди они были хорошие, да только не везло им в жизни... Правда?"
>>> sent_count(text)
В этом тексте 4 предложения.
>>> name = "NAME"
>>> input_path = "INPUT_PATH"
>>> print("\""+name+"\" - ERROR! File not found in \""+input_path+"\"")
"NAME" - ERROR! File not found in "INPUT_PATH"
# не лучше ли, "мальчики-налево, девочки-направо" ?
>>> print('"{0}" - ERROR! File not found in "{1}"'.format(name, input_path))
"NAME" - ERROR! File not found in "INPUT_PATH"
>>> print("\""+name+"\" - ERROR! File \""+name+"\" not found in \""+input_path+"\"")
"NAME" - ERROR! File "NAME" not found in "INPUT_PATH"
>>> print('"{0}" - ERROR! File "{0}" not found in "{1}"'.format(name, input_path))
"NAME" - ERROR! File "NAME" not found in "INPUT_PATH"
>>> import random
>>> numbers = range(100)
>>> random.sample(numbers, 10)
[0, 14, 94, 93, 22, 7, 45, 20, 61, 3]
>>> random.sample(numbers, 10)
[72, 73, 26, 11, 19, 71, 76, 45, 80, 23]
>>> numbers = list(range(10))
>>> random.shuffle(numbers)
>>> numbers
[2, 1, 7, 6, 9, 4, 0, 8, 3, 5]
>>> random.shuffle(numbers)
>>> numbers
[1, 6, 7, 9, 3, 8, 2, 5, 4, 0]