Python - 在另一个函数中使用函数来更改列表列表中的str [英] Python - using a function in another to change a str in a list of list

查看:280
本文介绍了Python - 在另一个函数中使用函数来更改列表列表中的str的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的功能回归:









Here's the return of my function:




[['Musique', 'Shawn Phillips', '2018-08-24', '2018-08-24'], ['Musique', "L'avenue Royale fête l'été!", '2018-08-25', '2018-08-25'], ['Musique', 'Perséides musicales', '2018-08-03', '2018-08-03']





我必须使用循环来搜索所有这些索引并替换所有日期,例如< pre> '2018-08-24'< / pre> 到一个int,然后用int替换所有这些日期。



现在,我需要放在这个函数中的另一个函数实际上是返回int的函数( obtain_date(date)),这个函数实际上有效。所以现在我很难在最初使用这个函数,所以我可以使用它的循环(我假设)将我的日期的所有str替换为int。





所以有效的功能叫做 obtain_date(日期)



我必须把它放在 obtain_events 请记住这是一个列表清单。



I have to use a loop to i can search all those index and replace all date like <pre> '2018-08-24'</pre> to an int and then replace all of those date with the int.

Now, the other function that i need to put in this one is actually the function thats returns the int(obtain_date(date)), this one actually works. So now im having a hard time using this function in the initial one so i can use a loop with it (im assuming) to replace all str of my date into int.


So the function that works is called obtain_date(date)

I have to put it in obtain_events Keep in my mind that this is a list of lists.






所以我的2个功能是:



obtain_events()

obtain_date (日期)



- obtain_date(日期)进入获取事件()



谢谢!



我尝试过的事情:



我试图用我的 obtain_date(date)在这样的循环中:





So my 2 functions involved are:

obtain_events()
obtain_date(date)

- obtain_date(date) goes in obtain_events()

Thanks!

What I have tried:

I've tried to use my obtain_date(date) in a loop like this:

year = '2018'
for liste in my_liste:                     #to reach my global list
          for element in liste:            # to reach every lists in my list
             if year in element:      #using '2018' as its in every str i modify
              element[5:] = obtain_date(date)          #[5:] = str after '2018

推荐答案

我昨天在你原来的问题中给了你答案:如何在列表中提取字符串的一部分并将其更改为int。 [ ^ ]。请不要重新发布相同的问题。
I gave you the answer yesterday in your original question: How do I extract a part of a string in a list and change it into an int.[^]. Please do not repost the same question.


这篇关于Python - 在另一个函数中使用函数来更改列表列表中的str的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆