[Tutor] Tutor Digest, Vol 195, Issue 23
Boi0
matthewrodrigues707 at gmail.com
Fri May 15 21:05:22 EDT 2020
I'm working on a text-based RPG, I am on a Windows, and I want the
inventory to open (by pressing i) without pressing enter.
On Fri, May 15, 2020 at 9:00 AM <tutor-request at python.org> wrote:
> Send Tutor mailing list submissions to
> tutor at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-request at python.org
>
> You can reach the person managing the list at
> tutor-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> Today's Topics:
>
> 1. Replace nth item with single value in each nested list (EK Esawi)
> 2. Inventory problem (Boi0)
> 3. Re: Inventory problem (DL Neil)
> 4. Re: Inventory problem (Alan Gauld)
> 5. Re: Replace nth item with single value in each nested list
> (Peter Otten)
>
>
>
> ---------- Forwarded message ----------
> From: EK Esawi <ekesawi at yahoo.com>
> To: "akleider at sonic.net" <akleider at sonic.net>
> Cc: Tutor Com <tutor at python.org>
> Bcc:
> Date: Fri, 15 May 2020 06:26:07 +0000 (UTC)
> Subject: [Tutor] Replace nth item with single value in each nested list
> Hi All--
>
>
> Thank you all for your input. It’s highly appreciated. With your help, I
> managed to produce something that works for me; but only works for nested
> lists with two entries. For more than two entire nested lists, it produces
> only 2 entries nested lists.
>
> Here is my formula:
>
> aa=[[x[0],60] if x[1] >= 3 else [x[0],x[1]] for x in a]
>
> a is my list
>
>
>
> Thanks again and have a nice weekend--EK
>
>
>
>
> ---------- Forwarded message ----------
> From: Boi0 <matthewrodrigues707 at gmail.com>
> To: Tutor at python.org
> Cc:
> Bcc:
> Date: Thu, 14 May 2020 23:06:13 -0700
> Subject: [Tutor] Inventory problem
> I'm trying to make an RPG and I came across the issue of the inventory. I
> want the inventory to be opened by simply pressing i. I've looked
> everywhere on the internet for a solution to this (relatively simple)
> problem. Could someone answer this for me?
>
>
>
>
> ---------- Forwarded message ----------
> From: DL Neil <PyTutor at danceswithmice.info>
> To: Tutor at python.org
> Cc:
> Bcc:
> Date: Fri, 15 May 2020 19:04:20 +1200
> Subject: Re: [Tutor] Inventory problem
> On 15/05/20 6:06 PM, Boi0 wrote:
> > I'm trying to make an RPG and I came across the issue of the inventory. I
> > want the inventory to be opened by simply pressing i. I've looked
> > everywhere on the internet for a solution to this (relatively simple)
> > problem. Could someone answer this for me?
>
>
> A Rocket-Propelled Grenade?
>
> As well as Python, which GUI are you employing?
> --
> Regards =dn
>
>
>
>
> ---------- Forwarded message ----------
> From: Alan Gauld <alan.gauld at yahoo.co.uk>
> To: tutor at python.org
> Cc:
> Bcc:
> Date: Fri, 15 May 2020 08:12:36 +0100
> Subject: Re: [Tutor] Inventory problem
> On 15/05/2020 07:06, Boi0 wrote:
> > I'm trying to make an RPG and I came across the issue of the inventory. I
> > want the inventory to be opened by simply pressing i.
>
> We need a bit more information. How does your RPG work?
> Is it in a GUI or a text terminal? Or a web page?
> Are you using a particular framework such as PyGame?
> Or a particular GUI or web framework?
>
> Also, when you say "simply pressing i" does that mean you want to
> detect the keypress regardless of what else s happening in the
> game and immediately present the inventory? Or is this within the
> context of a menu or command line in which case it may involve
> hitting "enter" too?
>
> Finally, we need to know which OS you are using since these
> kinds of operations are often platform specific.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
>
>
>
>
> ---------- Forwarded message ----------
> From: Peter Otten <__peter__ at web.de>
> To: tutor at python.org
> Cc:
> Bcc:
> Date: Fri, 15 May 2020 16:15:12 +0200
> Subject: Re: [Tutor] Replace nth item with single value in each nested list
> EK Esawi via Tutor wrote:
>
> > Hi All--
> >
> >
> > Thank you all for your input. It’s highly appreciated. With your help, I
> > managed to produce something that works for me; but only works for nested
> > lists with two entries. For more than two entire nested lists, it
> produces
> > only 2 entries nested lists.
> >
> > Here is my formula:
> >
> > aa=[[x[0],60] if x[1] >= 3 else [x[0],x[1]] for x in a]
> >
> > a is my list
>
> You can generalize this a little with slices
>
> aa = [x[:1] + [60 if x[1] >= 3 else x[1]] + x[2:] for x in a]
>
> but as was pointed out this is more complex than the inplace solution,
>
> for x in a:
> if x[1] >= 3:
> x[1] = 60
>
> needs to do more work, and requires more memory.
>
> If you have numpy around there is another alternative:
>
> b = numpy.array(a)
> b[:,1][b[:,1] >= 3] = 60
>
> Very concise, but I'd probably rewrite that with a helper variable
>
> b = numpy.array(a)
> c = b[:,1]
> c[c>=3] = 60
>
> or transpose the array.
>
>
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> https://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list