首页 \ 问答 \ Python列表索引拆分和操作(Python list index splitting and manipulation)

Python列表索引拆分和操作(Python list index splitting and manipulation)

我的问题似乎很简单,但对于像我这样的Python新手来说,这对我来说太复杂了,所以情况如下:

我需要列出如下列表:

L = [(a, b, c), (d, e, d), (etc, etc, etc), (etc, etc, etc)]

并将每个索引设置为一个单独的列表,以便我可以专门从每个索引中提取元素。 问题是我实际上使用的列表包含数百个索引,比如上面的那些索引,我不能这样做:

L_new = list(L['insert specific index here'])

对于每一个人来说,这意味着会填充与第一个列表中的单个索引相对应的数百个列表的内存,并且从我的角度来看,将花费太多时间和内存。 所以我的问题是,如何分开这些索引,然后从它们中提取单个部分,而无需创建数百个单独的列表(至少不需要数百个单独的行来创建它们)。


My question seems simple, but for a novice to python like myself this is starting to get too complex for me to get, so here's the situation:

I need to take a list such as:

L = [(a, b, c), (d, e, d), (etc, etc, etc), (etc, etc, etc)]

and make each index an individual list so that I may pull elements from each index specifically. The problem is that the list I am actually working with contains hundreds of indices such as the ones above and I cannot make something like:

L_new = list(L['insert specific index here'])

for each one as that would mean filling up the memory with hundreds of lists corresponding to individual indices of the first list and would be far too time and memory consuming from my point of view. So my question is this, how can I separate those indices and then pull individual parts from them without needing to create hundreds of individual lists (at least to the point where I wont need hundreds of individual lines to create them).


原文:https://stackoverflow.com/questions/17238781
更新时间:2022-11-30 08:11

最满意答案

routes.MapRoute("Route 1", // Route name
                "product {prodId}/{action}/{code}",
                new 
                { 
                    controller = "Product",   //default controller=Product
                    action = "Index",         //default action= Index
                    prodId = 12,              //default prodId=12
                    code=UrlParameter.Optional // code is optional
                }
            );






www.xx.com/product 12/         >> Action: Overview,  
                                    >> ProdId=12 passed as a param

www.xx.com/product 12/Overview >> Action: Overview,  
                                    >> ProdId=12 passed as a param

www.xx.com/product 12/Results  >> Action: Results,  
                                    >> ProdId=12 passed as a param

www.xx.com/product 12/Product  >> Action: Product, 
                                    >> ProdId=12 passed as a param
                                    >> Code=""   passed as a param

www.xx.com/product 12/Product/123 >> Action: Index, 
                                    >> ProdId=12 passed as a param
                                    >> Code= 123 passed as a param

routes.MapRoute("Route 1", // Route name
                "product {prodId}/{action}/{code}",
                new 
                { 
                    controller = "Product",   //default controller=Product
                    action = "Index",         //default action= Index
                    prodId = 12,              //default prodId=12
                    code=UrlParameter.Optional // code is optional
                }
            );






www.xx.com/product 12/         >> Action: Overview,  
                                    >> ProdId=12 passed as a param

www.xx.com/product 12/Overview >> Action: Overview,  
                                    >> ProdId=12 passed as a param

www.xx.com/product 12/Results  >> Action: Results,  
                                    >> ProdId=12 passed as a param

www.xx.com/product 12/Product  >> Action: Product, 
                                    >> ProdId=12 passed as a param
                                    >> Code=""   passed as a param

www.xx.com/product 12/Product/123 >> Action: Index, 
                                    >> ProdId=12 passed as a param
                                    >> Code= 123 passed as a param

相关问答

更多
  • 主观普遍性(采取一撮盐): 首先,您对公司使用公司(单数),但是您使用联系人(复数)作为联系人。 从结构的角度来看,没有什么不对,但如果你的复数形式一致,你的用户会感谢你。 我会在两种情况下都使用复数形式,但这只是我的偏好......它看起来更像英语。 您也可以使用小写字母作为联系人,但大写则为公司。 看起来不专业。 接下来令人困惑的是您使用了两个{id}参数,一个用于公司,一个用于联系人。 我认为这些分别是公司和联系人的ID。 但是我很困惑,但作为人类,我能够像计算机一样推断上下文。 所以你最好在你的路线 ...
  • routes.MapRoute("Route 1", // Route name "product {prodId}/{action}/{code}", new { controller = "Product", //default controller=Product action = "Index", // ...
  • 在考虑周末之后,我决定使用“UseNamespaceFallback”。 我还实现了用户角色来管理每个用户可以访问的区域。 我认为这是一种更好的方法,因为我已经阅读了建议永远不要使用命名空间作为身份验证的方法。 After thinking about this though the weekend I decided to use "UseNamespaceFallback". I also implemented user roles to manage which areas each user ha ...
  • 使用Request对象的Url属性 。 public ActionResult MyAction() { var url = Request.Url; /// ..... return View(); } 这将返回一个Uri对象与你需要的一切 。 您可能也对控制器的RouteData属性感兴趣,该属性提供了有关解析路线的更多详细信息。 Use the Url property of the Request object. public ActionResult MyAc ...
  • 您只需要忽略第一个路径的路径字符串中的操作: routes.MapRoute( "picks", "picks/{teamID}/{week}", new { controller = "Picks", action = "Index", teamID = UrlParameter.Optional, week = UrlParameter.Optional }); 请记住在更通用的路线之上 ...
  • 其他人已经提出了很多建议,但是让我在这里提出一些其他的建议。 操作方法选择器 为了保持控制器操作的清洁,您可以编写一个操作方法选择器属性来创建两个简单的操作: [ActionName("Index")] public ActionResult IndexNonActivated(int id) { ... } [ActionName("Index")] [UserAccountActivated] public ActionResult IndexActivated(int id) { . ...
  • 按照@BrettSmith发布的建议,我想出了以下解决方案: 我添加了第二个路径,其中包含锚点和约束,因此只有在指定锚点时才会选择此路径。 routes.MapRoute( "DocAnchor", // Route name "{controller}/{action}/{id}#{anchor}", // URL with parameters new { controller = "Home", action = "Index", id = UrlPar ...
  • 您应该将Year参数传递给BeginForm(),如: <% using (Html.BeginForm("Results", "Archive", new { year = DateTime.Now.Year })) { // form } %> You should pass the Year parameter to the BeginForm(), like: <% using (Html.BeginForm("Results", "Archiv ...
  • 自定义路由中有一个示例(根据您的情况进行了修改)。 Global.asax中: routes.MapRoute( "BrandDetails", "Brands/{brandID}", new { controller = "Brands", action = "Details" }, new { brandID = @"\d+" } ); routes.MapRoute( "Default", "{controller}/{action}/{id}", ...
  • 我最后使用以下答案在SignalR代码中修复此问题并提交拉取请求。 添加非mvc路由时,Html.ActionLink构造错误的链接 https://github.com/SignalR/SignalR/pull/19 I ended up fixing this in the SignalR code using the below answer and submitting a pull request. Html.ActionLink construct wrong link when a non-m ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)