“Python Zip” Kod odpowiedzi

Folder zip Python

import shutil
shutil.make_archive(output_filename, 'zip', dir_name)
DigitalBorder

Folder zip Python

import os
import zipfile

def zip_directory(folder_path, zip_path):
    with zipfile.ZipFile(zip_path, mode='w') as zipf:
        len_dir_path = len(folder_path)
        for root, _, files in os.walk(folder_path):
            for file in files:
                file_path = os.path.join(root, file)
                zipf.write(file_path, file_path[len_dir_path:])
                
zip_directory('C:/FolderToZip', 'C:/Folder.zip')
Gentle Gazelle

Python Zip ()

languages = ['Java', 'Python', 'JavaScript']
versions = [14, 3, 6]

result = zip(languages, versions)
print(list(result))

# Output: [('Java', 14), ('Python', 3), ('JavaScript', 6)]

print(dict(result))

# Output: {'Java': 14, 'Python': 3, 'JavaScript': 6}
Evil Echidna

Funkcja zip Python

namelist = ["Avish", "Piyush", "Tom"]
agelist = [17, 22, 38]

for name, age in zip(namelist, agelist):
    print(name, age)

# Avish 17
# Piyush 22
# Tom 38
patrick204nqh

Python Zip

>>> a = [1, 2, 3]
>>> b = [4, 5, 6]
>>> c = zip(a, b)
>>> print(c)
<zip object at 0x7f55cfca3080>
>>> list(c)
[(1, 4), (2, 5), (3, 6)]
Filthy Fox

Zip Python

>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> list(zipped)
[(1, 4), (2, 5), (3, 6)]
>>> x2, y2 = zip(*zip(x, y))
>>> x == list(x2) and y == list(y2)
True
Helpless Hare

Odpowiedzi podobne do “Python Zip”

Pytania podobne do “Python Zip”

Więcej pokrewnych odpowiedzi na “Python Zip” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu