Python
69
Вклад в тег
import os
from functools import reduce
def get_struct(rootdir):
dir = {}
rootdir = rootdir.rstrip(os.sep)
start = rootdir.rfind(os.sep) + 1
for path, dirs, files in os.walk(rootdir):
folders = path[start:].split(os.sep)
subdir = dict.fromkeys(files)
parent = reduce(dict.get, folders[:-1], dir)
parent[folders[-1]] = subdir
return dir
>>>pprint.pprint(get_struct("/home/hasan/Загрузки"), indent=4)
{ 'Загрузки': { '.directory': None,
'CS15Setup.exe': None,
'CrossOver 16.2.5': { 'Crack': { 'winewrapper.exe.so': None},
'CrossOver 16.2.5.md5': None,
'crossover-16.2.5-1.rpm': None,
'crossover_16.2.5-1.deb': None,
'install-crossover-16.2.5.bin': None},
'Effective_Python_proglib.pdf.crdownload': None,
'Grokaem_algoritmy_Illyustrirovannoe_posobie_dlya_pr.rar': None,
'Hodyachij.zamok.2004.DUAL.BDRip.XviD.AC3.-HQCLUB.avi': None,
'IDM-6.28.17': { 'IDM-6.28.17.exe': None,
'Тихая установка.cmd': None},
'IDM-6.28.17.zip': None,
'IMG_20171002_102640.jpg': None,
'IMG_20171002_102653.jpg': None,
'IMG_20171006_213030.jpg': None,
'IMG_20171009_185922.jpg': None,
'IMG_20171009_185934.jpg': None,
'IMG_20171009_205812.jpg': None,
'IMG_20171009_210242.jpg': None,
'IMG_20171009_210311.jpg': None,
'IMG_20171009_210355.jpg': None,
'Postroenie_sistem_mashinnogo_obuchenia_na_yazyke_Python.zip': None,
'SIMS3_Repack.iso': None,
'TORRENT': {},
'[rutor.is]Hodyachij.zamok.2004.DUAL.BDRip.XviD.AC3.-HQCLU.torrent': None,
'[rutor.is]SIMS3_Repack.torrent': None,
'[rutor.is]Teoriya.Bolshogo.Vzriva.(5.sezon.01-24.serii.iz.torrent': None,
'[rutor.is]The Big Bang Theory.s05.torrent': None,
'[rutor.is]Zakljate._Nashi_dni_The_Crucifixion_2017_WEB-DL.torrent': None,
'payeer_mastercard_ru.pdf': None,
'risovach.ru.jpg': None,
'selecttv_latest_07_09_2017.apk': None,
'st_7972_1b.jpg': None,
'thenightmarebeforechristmas19933d720pblurayx264ytsag-english-110597': { 'The Nightmare Before Christmas en.srt': None},
'thenightmarebeforechristmas19933d720pblurayx264ytsag-english-110597.zip': None,
'Не подтвержден 741176.crdownload': None,
'Силен Д., Мейсман А. - Основы Data Science и Big Data. Python и наука о данных - 2017.PDF': None}}
if not b and ( c=='mod' or c=='/' or c=='div'):
print("Делеение на ноль")
if not b and c in ['/','%', 'mod', 'div']:
print("Делеение на ноль")
a = float(input())
b = float(input())
c = input()
z_div = 'Деление на ноль!"
OPERATORS = {
"+": a + b,
"-": a - b,
"*": a * b,
"/": a / b if b else z_div,
"mod": a % b if b else z_div,
"div": a // b if b else z_div,
"pow": a ** b
}
print(OPERATORS[c])
a = float(input())
b = float(input())
c = input()
z_div = 'Деление на ноль!'
OPERATORS = {
"+": lambda x, y: x + y,
"-": lambda x, y: x - y,
"*": lambda x, y: x * y,
"/": lambda x, y: x / y if y else None,
"mod": lambda x, y: x % y if y else None,
"div": lambda x, y: x // y if y else None,
"pow": lambda x, y: x ** y
}
print(OPERATORS[c](a, b))
a = input()
b = input()
c = input()
OPERATORS = {
"+": "+",
"-": "-",
"*": "*",
"/": "/",
"mod": "%",
"div": "//",
"pow": "**"
}
if not float(b) and c in ['/','%', 'mod', 'div']:
print('Деление на ноль!')
else:
print(
eval(
a + OPERATORS[c] + b
)
)