在各种条件下加入列表元素
对于此列表,
pays_list=["France","francais","€200", "1kg","20€","Espagne","espagnol","€20",
"Allemagne","allemand","deutsch","€100","2kg", "300€",
"Belgique","belge","frite","€30"]
pays_concatenate=[]
for i, elm in enumerate(pays_list):
if "€" in elm:
del pays_list[i]
pays_list=pays_list
for i in pays_list:
for e in i:
if any(e in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for e in i):
print(i)
“ i”将等于带有大写字母的元素...(法国,espagne等...)
之前添加元素
我想在下一个大写字母i
pays_concatenate=["France francais","Espagne espagnol",
"Allemagne allemand deutsch",
"Belgique belge frite"]
For this list
pays_list=["France","francais","€200", "1kg","20€","Espagne","espagnol","€20",
"Allemagne","allemand","deutsch","€100","2kg", "300€",
"Belgique","belge","frite","€30"]
pays_concatenate=[]
for i, elm in enumerate(pays_list):
if "€" in elm:
del pays_list[i]
pays_list=pays_list
for i in pays_list:
for e in i:
if any(e in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for e in i):
print(i)
"i" will be equal to elements with a capital letter...(France, Espagne etc ...)
I want to add the elements before the next capital letter
I except this output
pays_concatenate=["France francais","Espagne espagnol",
"Allemagne allemand deutsch",
"Belgique belge frite"]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
itertools.groupby
将字符串分组为具有和不带有“€”
的那些字符串,并使用“” :
Use
itertools.groupby
to group the strings into those with and without a"€"
, and join each group with" "
:感谢Samwise,我完成了您的代码以使我的输出
和输出:
Thank Samwise, i complete your code to have my output
and my output :