Python Forum
Simple code question about lambda and tuples
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple code question about lambda and tuples
#1
I have a simple code:

my_tuple = (0,1,2,3,4,5,6)
foo = list(filter(lambda x: x-0, my_tuple))

print(foo)
I know what the output is and that it removes the first entry, the 0. I could also change it as follows:

my_tuple = (0,1,2,3,4,5,6)
foo = list(filter(lambda x: x-0 and x-1, my_tuple))

print(foo)
I thought that tuples are immutable? How are the 0 and 1 removed? How does this work and what is this x-0 actually doing?
Yoriz write Oct-03-2021, 02:22 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Simple code question about lambda and tuples - by JasPyt - Oct-03-2021, 01:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Very Beginner question on simple variables Harvy 1 201 Apr-12-2024, 12:03 AM
Last Post: deanhystad
  Help with simple code JacobSkinner 1 337 Mar-18-2024, 08:08 PM
Last Post: deanhystad
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 494 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Simple Question - ' defined as "a". ?' Ryan012 10 1,648 May-27-2023, 06:03 PM
Last Post: Ryan012
  Very simple question about filenames and backslashes! garynewport 4 1,971 Jan-17-2023, 05:02 AM
Last Post: deanhystad
  Python Tkinter Simple Multithreading Question AaronCatolico1 5 1,596 Dec-14-2022, 11:35 PM
Last Post: deanhystad
  help me simple code result min and max number abrahimusmaximus 2 916 Nov-12-2022, 07:52 AM
Last Post: buran
  A simple "If...Else" question from a beginner Serena2022 6 1,762 Jul-11-2022, 05:59 AM
Last Post: Serena2022
  Simple encoding code ebolisa 3 1,463 Jun-18-2022, 10:59 AM
Last Post: deanhystad
  How would you (as an python expert) make this code more efficient/simple coder_sw99 3 1,820 Feb-21-2022, 10:52 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020