小编new*_* 21的帖子

Python - 使用For循环水平翻转图像

我正在尝试使用for循环逐个像素地水平翻转图像.如果可能的话,试着纠正我所拥有的东西,而不是提供一种完全不同的方法(即使更有效率或pythonic),以帮助我和其他人从我的错误中吸取教训.谢谢你的帮助.

def flip(img):
   width = img.size[0]
   height = img.size[1]
   for y in range(height):
       for x in range(width):
           left = img.getpixel((x, y))
           right = img.getpixel((width - 1 - x, y))
           img.putpixel((width - 1 - x, y), left)
           img.putpixel((x, y), right)
Run Code Online (Sandbox Code Playgroud)

python for-loop image flip

2
推荐指数
1
解决办法
5299
查看次数

Python 字符串比较 - 元音

我正在尝试编写一个 Python 函数,它将两个字符串作为参数并返回它们是否具有相同的元音(数量无关紧要)。

因此 ('indeed','bed') 应该返回 true,但是 ('indeed','irate') 应该返回 false。

我坚持这个相当可怕的尝试......

def vocalizer(string_a,string_b):
vowels = ['a', 'e', 'i', 'o', 'u']
result = ''
result_2 = ''
for character in string_a:
    if character in vowels:
       result = result + character
       for item in string_b:
            if item in vowels:
               result_2 = result_2 + item
               for vowel in result:
                    if vowel not in list(result_2):
                       return False
                    else:
                       if vowel in list(result_2):
                          return True
Run Code Online (Sandbox Code Playgroud)

python string compare

0
推荐指数
1
解决办法
1166
查看次数

标签 统计

python ×2

compare ×1

flip ×1

for-loop ×1

image ×1

string ×1