# 列表取交集、差集、并集
a = ['a', 'b', 'c']
b = ['a', 'b', 'd']
# 差集
print([i for i in a if i not in b])
# 反向差集
print(list(set(b) - set(a)))
# 并集
print(list(set(b) | set(a)))
# -*- coding:utf-8 -*-
# @Time :2021-5-27 22:02
# @AUTHOR :MUFENG12138
# @SOFTWARE :lxf_train
# 统计列表中正负数个数
a = [1, 3, 5, 7, 9, 11, 0, -2, -4, -6, -8, -10]
m = n = 0
for i in a:
if i < 0:
m += 1
elif i > 0:
n += 1
print("正数个数为:{}".format(n))
print("负数个数为:{}".format(m))
# -*- coding:utf-8 -*-
# @Time :2021-5-27 22:02
# @AUTHOR :MUFENG12138
# @SOFTWARE :lxf_train
# 请把两个列表提取作为字典
keys = ['name', 'age', 'city', '微信公众号']
values = ['CoCo', 18, 'ShenZhen', 'mufeng12138']
ans = {'name': 'CoCo', 'age': 18, 'city': 'ShenZhen', '微信公众号': 'mufeng12138'}
an = zip(keys, values)
# 将压缩的数据转换为字典
print(dict(an))
# x, y=zip(*zip(an))
# 组合并用元组的格式输出
print(*zip(keys, values))
# 失败的尝试
print(*zip(an))
print(list(*zip(an)))
# 三个参数与空元素组成新元组。还不太懂
print(*zip(zip(keys, values)))
# print(x)
# https://www.cnblogs.com/kenny-feng/p/11368477.html
# https://www.runoob.com/python/python-func-zip.html
# -*- coding:utf-8 -*-
# @Time :2021-5-27 22:02
# @AUTHOR :MUFENG12138
# @SOFTWARE :lxf_train
# 请把字符串"MUFENG12138"里的字符串逐个打印出来
a = 'MUFENG12138'
for i in a:
print(i)
# -*- coding:utf-8 -*-
# @Time :2021-5-27 22:02
# @AUTHOR :MUFENG12138
# @SOFTWARE :lxf_train
# 请把字符串"MUFENG:12138"里的字符串按冒号分割,倒序打印:"12138:MUFENG"
a = 'MUFENG:12138'
print(a)
b=list(a.split(":"))
print(b)
b.reverse()
print(b)
print(":".join(b))
# -*- coding:utf-8 -*-
# @Time :2021-5-28 22:02
# @AUTHOR :MUFENG12138
# @SOFTWARE :lxf_train
# 找到照片定位
# https://mp.weixin.qq.com/s/YT7CZ05GhZYRi1jpzIkngg
# import exifread
# f1=r"D:\Users\Desktop\01.jpg"
# f2=r"D:\Users\Desktop\02.jpg"
#
# tags=exifread.process_file(f2)
# print(tags)
import requests
import exifread
class GetPhotoInfo:
def __init__(self, photo):
self.photo = photo
self.ak = ''# 该处填写百度地图开放平台中申请的AK
self.location = self.get_photo_info()
def get_photo_info(self, ):
with open(self.photo, 'rb') as f:
tags = exifread.process_file(f)
try:
print('拍摄时间:', tags['EXIF DateTimeOriginal'])
print('照相机制造商:', tags['Image Make'])
print('照相机型号:', tags['Image Model'])
print('照片尺寸:', tags['EXIF ExifImageWidth'], tags['EXIF ExifImageLength'])
lat_ref = tags["GPS GPSLatitudeRef"].printable
lat = tags["GPS GPSLatitude"].printable[1:-1].replace(" ", "").replace("/", ",").split(",")
lat = float(lat[0]) + float(lat[1]) / 60 + float(lat[2]) / float(lat[3]) / 3600
if lat_ref != "N":
lat = lat * (-1)
lon_ref = tags["GPS GPSLongitudeRef"].printable
lon = tags["GPS GPSLongitude"].printable[1:-1].replace(" ", "").replace("/", ",").split(",")
lon = float(lon[0]) + float(lon[1]) / 60 + float(lon[2]) / float(lon[3]) / 3600
if lon_ref != "E":
lon = lon * (-1)
except KeyError:
return "ERROR:照片中不包含经纬度等信息。"
else:
print("经纬度:", lat, lon)
return lat, lon
def get_location(self):
url = 'http://api.map.baidu.com/reverse_geocoding/v3/?ak={}&output=json' \
'&coordtype=wgs84ll&location={},{}'.format(self.ak, *self.location)
response = requests.get(url).json()
status = response['status']
if status == 0:
address = response['result']['formatted_address']
print('详细地址:', address)
else:
print('baidu_map error')
if __name__ == '__main__':
f1 = r"D:\Users\Desktop\01.jpg"
f2 = r"D:\Users\Desktop\02.jpg"
Main = GetPhotoInfo(f2)
Main.get_location()